fix: gate gateway restarts and discord abort reconnects

This commit is contained in:
Peter Steinberger
2026-01-18 23:25:04 +00:00
parent e97bcf4dae
commit d802844bd6
11 changed files with 143 additions and 8 deletions

41
src/infra/restart.test.ts Normal file
View File

@@ -0,0 +1,41 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
__testing,
consumeGatewaySigusr1RestartAuthorization,
isGatewaySigusr1RestartExternallyAllowed,
scheduleGatewaySigusr1Restart,
setGatewaySigusr1RestartPolicy,
} from "./restart.js";
describe("restart authorization", () => {
beforeEach(() => {
__testing.resetSigusr1State();
vi.useFakeTimers();
vi.spyOn(process, "kill").mockImplementation(() => true);
});
afterEach(async () => {
await vi.runOnlyPendingTimersAsync();
vi.useRealTimers();
vi.restoreAllMocks();
__testing.resetSigusr1State();
});
it("consumes a scheduled authorization once", async () => {
expect(consumeGatewaySigusr1RestartAuthorization()).toBe(false);
scheduleGatewaySigusr1Restart({ delayMs: 0 });
expect(consumeGatewaySigusr1RestartAuthorization()).toBe(true);
expect(consumeGatewaySigusr1RestartAuthorization()).toBe(false);
await vi.runAllTimersAsync();
});
it("tracks external restart policy", () => {
expect(isGatewaySigusr1RestartExternallyAllowed()).toBe(false);
setGatewaySigusr1RestartPolicy({ allowExternal: true });
expect(isGatewaySigusr1RestartExternallyAllowed()).toBe(true);
});
});