24 lines
1.8 KiB
TypeScript
24 lines
1.8 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import {test} from "node:test"
|
|
import {executeDatabaseOperation} from "./system-database-operation.js"
|
|
function fixture(fail: string[] = []) {
|
|
const calls:string[]=[]
|
|
const step=(name:string)=>async()=>{calls.push(name);if(fail.includes(name))throw Error(name+" failed")}
|
|
return {calls,deps:{stopListener:step("stop listener"),stopScheduler:step("stop scheduler"),startListener:step("start listener"),startScheduler:step("start scheduler")},run:async()=>{await step("command")();return {cleanupError:"cleanup warning"}}}
|
|
}
|
|
test("confirmed command survives independent restart failures",async()=>{
|
|
for(const fail of [[],["start listener"],["start scheduler"],["start listener","start scheduler"]]){
|
|
const f=fixture(fail);const result=await executeDatabaseOperation(f.run,f.deps)
|
|
assert.equal(result.cleanupError,"cleanup warning");assert.equal(!!result.listenerError,fail.includes("start listener"));assert.equal(!!result.schedulerError,fail.includes("start scheduler"))
|
|
assert.deepEqual(f.calls,["stop listener","stop scheduler","command","start listener","start scheduler"])
|
|
}
|
|
})
|
|
test("core failure survives restart failures without command retry",async()=>{
|
|
const f=fixture(["command","start listener","start scheduler"])
|
|
await assert.rejects(executeDatabaseOperation(f.run,f.deps),/command failed/)
|
|
assert.equal(f.calls.filter(s=>s==="command").length,1);assert.deepEqual(f.calls.slice(-2),["start listener","start scheduler"])
|
|
})
|
|
test("stop failure prevents command and still attempts both restarts",async()=>{
|
|
for(const step of ["stop listener","stop scheduler"]){const f=fixture([step,"start listener"]);await assert.rejects(executeDatabaseOperation(f.run,f.deps),new RegExp(step+" failed"));assert.equal(f.calls.includes("command"),false);assert.deepEqual(f.calls.slice(-2),["start listener","start scheduler"])}
|
|
})
|