import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { __testing, deferGatewayRestartUntilIdle, type RestartDeferralHooks } from "./restart.js";
describe("deferGatewayRestartUntilIdle timeout", () => {
beforeEach(() => {
vi.useFakeTimers();
__testing.resetSigusr1State(); // Add a listener so emitGatewayRestart uses process.emit instead of process.kill
process.on("SIGUSR1", () => {});
});
// Advance to just before 5 minutes — should NOT have timed out yet
vi.advanceTimersByTime(299_999);
expect(hooks.onTimeout).not.toHaveBeenCalled();
// Advance past 5 minutes — should time out
vi.advanceTimersByTime(1);
expect(hooks.onTimeout).toHaveBeenCalledOnce();
expect(hooks.onReady).not.toHaveBeenCalled();
});
// Advance to just before 2 minutes
vi.advanceTimersByTime(119_999);
expect(hooks.onTimeout).not.toHaveBeenCalled();
// Advance past 2 minutes
vi.advanceTimersByTime(1);
expect(hooks.onTimeout).toHaveBeenCalledOnce();
});
it("calls onReady and does not timeout when pending count drops to 0", () => { const hooks: RestartDeferralHooks = {
onTimeout: vi.fn(),
onReady: vi.fn(),
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.