Files
MikrotikManager/tests/unit/server-poll-batch.test.ts
T

16 lines
734 B
TypeScript

import assert from "node:assert/strict"
import { test } from "node:test"
import { pollServers } from "../../lib/server-operations.js"
test("full poll batches serialize global maintenance and never retry a failed target",async()=>{
let active=0,maxActive=0
const calls:string[]=[]
const results=await pollServers(["1","2","1","3"],async id=>{
calls.push(id);active++;maxActive=Math.max(maxActive,active)
try{await new Promise<void>(done=>setImmediate(done));if(id==="2")throw Error("uncertain; refresh first")}
finally{active--}
})
assert.equal(maxActive,1)
assert.deepEqual(calls,["1","2","3"])
assert.deepEqual(results,[{id:"1",error:null},{id:"2",error:"uncertain; refresh first"},{id:"3",error:null}])
})