fix(background-agent): mock process.exit in forced-exit tests
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -89,6 +89,7 @@ describe("#given process cleanup registration", () => {
|
|||||||
const sigintListenersBefore = process.listeners("SIGINT")
|
const sigintListenersBefore = process.listeners("SIGINT")
|
||||||
const setTimeoutSpy = spyOn(globalThis, "setTimeout")
|
const setTimeoutSpy = spyOn(globalThis, "setTimeout")
|
||||||
const clearTimeoutSpy = spyOn(globalThis, "clearTimeout")
|
const clearTimeoutSpy = spyOn(globalThis, "clearTimeout")
|
||||||
|
const exitSpy = spyOn(process, "exit").mockImplementation((() => undefined) as never)
|
||||||
// Re-enable forced exit so we can verify setTimeout/clearTimeout are called
|
// Re-enable forced exit so we can verify setTimeout/clearTimeout are called
|
||||||
__enableScheduledForcedExitForTesting()
|
__enableScheduledForcedExitForTesting()
|
||||||
|
|
||||||
@@ -109,13 +110,42 @@ describe("#given process cleanup registration", () => {
|
|||||||
|
|
||||||
expect(setTimeoutSpy).toHaveBeenCalledTimes(1)
|
expect(setTimeoutSpy).toHaveBeenCalledTimes(1)
|
||||||
expect(clearTimeoutSpy).toHaveBeenCalledTimes(1)
|
expect(clearTimeoutSpy).toHaveBeenCalledTimes(1)
|
||||||
|
expect(exitSpy).toHaveBeenCalledWith(0)
|
||||||
} finally {
|
} finally {
|
||||||
|
exitSpy.mockRestore()
|
||||||
setTimeoutSpy.mockRestore()
|
setTimeoutSpy.mockRestore()
|
||||||
clearTimeoutSpy.mockRestore()
|
clearTimeoutSpy.mockRestore()
|
||||||
__disableScheduledForcedExitForTesting()
|
__disableScheduledForcedExitForTesting()
|
||||||
process.exitCode = 0
|
process.exitCode = 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("#when cleanup finishes after SIGTERM #then process exits after cleanup", async () => {
|
||||||
|
const sigtermListenersBefore = process.listeners("SIGTERM")
|
||||||
|
const exitSpy = spyOn(process, "exit").mockImplementation((() => undefined) as never)
|
||||||
|
const shutdown = mock(async () => {
|
||||||
|
await Promise.resolve()
|
||||||
|
})
|
||||||
|
const manager = { shutdown }
|
||||||
|
registeredManagers.push(manager)
|
||||||
|
__enableScheduledForcedExitForTesting()
|
||||||
|
|
||||||
|
try {
|
||||||
|
registerManagerForCleanup(manager)
|
||||||
|
|
||||||
|
const sigtermListener = getNewListener("SIGTERM", sigtermListenersBefore)
|
||||||
|
|
||||||
|
sigtermListener()
|
||||||
|
await flushMicrotasks()
|
||||||
|
|
||||||
|
expect(shutdown).toHaveBeenCalledTimes(1)
|
||||||
|
expect(exitSpy).toHaveBeenCalledWith(0)
|
||||||
|
} finally {
|
||||||
|
exitSpy.mockRestore()
|
||||||
|
__disableScheduledForcedExitForTesting()
|
||||||
|
process.exitCode = 0
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#given multiple cleanup managers", () => {
|
describe("#given multiple cleanup managers", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user