make kestrel a tak server, so that it can send and receive pois as cots data
Some checks failed
ci/woodpecker/pr/pr Pipeline failed
Some checks failed
ci/woodpecker/pr/pr Pipeline failed
This commit is contained in:
81
test/integration/shutdown.spec.js
Normal file
81
test/integration/shutdown.spec.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { registerCleanup, graceful, initShutdownHandlers, clearCleanup } from '../../server/utils/shutdown.js'
|
||||
|
||||
describe('shutdown integration', () => {
|
||||
let originalExit
|
||||
let exitCalls
|
||||
let originalOn
|
||||
|
||||
beforeEach(() => {
|
||||
clearCleanup()
|
||||
exitCalls = []
|
||||
originalExit = process.exit
|
||||
process.exit = vi.fn((code) => {
|
||||
exitCalls.push(code)
|
||||
})
|
||||
originalOn = process.on
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.exit = originalExit
|
||||
process.on = originalOn
|
||||
clearCleanup()
|
||||
})
|
||||
|
||||
it('initializes signal handlers', () => {
|
||||
const handlers = {}
|
||||
process.on = vi.fn((signal, handler) => {
|
||||
handlers[signal] = handler
|
||||
})
|
||||
initShutdownHandlers()
|
||||
expect(process.on).toHaveBeenCalledWith('SIGTERM', expect.any(Function))
|
||||
expect(process.on).toHaveBeenCalledWith('SIGINT', expect.any(Function))
|
||||
process.on = originalOn
|
||||
})
|
||||
|
||||
it('signal handler calls graceful', async () => {
|
||||
const handlers = {}
|
||||
process.on = vi.fn((signal, handler) => {
|
||||
handlers[signal] = handler
|
||||
})
|
||||
initShutdownHandlers()
|
||||
const sigtermHandler = handlers.SIGTERM
|
||||
expect(sigtermHandler).toBeDefined()
|
||||
await sigtermHandler()
|
||||
expect(exitCalls.length).toBeGreaterThan(0)
|
||||
process.on = originalOn
|
||||
})
|
||||
|
||||
it('signal handler handles graceful error', async () => {
|
||||
const handlers = {}
|
||||
process.on = vi.fn((signal, handler) => {
|
||||
handlers[signal] = handler
|
||||
})
|
||||
initShutdownHandlers()
|
||||
const sigintHandler = handlers.SIGINT
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
registerCleanup(async () => {
|
||||
throw new Error('Force error')
|
||||
})
|
||||
await sigintHandler()
|
||||
expect(exitCalls.length).toBeGreaterThan(0)
|
||||
process.on = originalOn
|
||||
})
|
||||
|
||||
it('covers timeout path in graceful', async () => {
|
||||
registerCleanup(async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 40000))
|
||||
})
|
||||
graceful()
|
||||
await new Promise(resolve => setTimeout(resolve, 100))
|
||||
expect(exitCalls.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('covers graceful catch block', async () => {
|
||||
registerCleanup(async () => {
|
||||
throw new Error('Test error')
|
||||
})
|
||||
await graceful()
|
||||
expect(exitCalls.length).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user