Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
Remove fire-and-forget SIGTERM/SIGINT handlers from usage.ts (race condition with pool.end() in index.ts). Instead, await flushDirtyEntries() in the index.ts shutdown orchestrator between stopping the server and closing the DB pool.
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
vi.unmock("../middleware/usage.js");
|
|
|
|
describe("usage shutdown race condition fix", () => {
|
|
it("should NOT register SIGTERM/SIGINT handlers as module-level side effects", async () => {
|
|
const onSpy = vi.spyOn(process, "on");
|
|
vi.resetModules();
|
|
|
|
// Track which signals usage.ts registers
|
|
const signalsBefore = onSpy.mock.calls.map(c => c[0]);
|
|
|
|
await import("../middleware/usage.js");
|
|
|
|
const signalsAfter = onSpy.mock.calls.map(c => c[0]);
|
|
const newSignals = signalsAfter.slice(signalsBefore.length);
|
|
|
|
// usage.ts should NOT register SIGTERM or SIGINT handlers
|
|
const usageSignals = newSignals.filter(s => s === "SIGTERM" || s === "SIGINT");
|
|
expect(usageSignals).toEqual([]);
|
|
|
|
onSpy.mockRestore();
|
|
});
|
|
|
|
it("should export flushDirtyEntries for external shutdown orchestration", async () => {
|
|
vi.resetModules();
|
|
const usageMod = await import("../middleware/usage.js");
|
|
expect(typeof usageMod.flushDirtyEntries).toBe("function");
|
|
});
|
|
});
|