



























@@ -483,6 +483,85 @@ describe("infra runtime", () => {
483483}
484484});
485485486+it("bypasses the pre-restart deferral check when requested", async () => {
487+const emitSpy = vi.spyOn(process, "emit");
488+const pendingCheck = vi.fn(() => 5);
489+const handler = () => {};
490+process.on("SIGUSR1", handler);
491+try {
492+setPreRestartDeferralCheck(pendingCheck);
493+scheduleGatewaySigusr1Restart({
494+delayMs: 0,
495+reason: "update.run",
496+skipDeferral: true,
497+});
498+499+await vi.advanceTimersByTimeAsync(0);
500+501+expect(pendingCheck).not.toHaveBeenCalled();
502+expect(emitSpy).toHaveBeenCalledWith("SIGUSR1");
503+expect(peekGatewaySigusr1RestartReason()).toBe("update.run");
504+} finally {
505+process.removeListener("SIGUSR1", handler);
506+}
507+});
508+509+it("upgrades an already scheduled restart to bypass deferral", async () => {
510+const emitSpy = vi.spyOn(process, "emit");
511+const pendingCheck = vi.fn(() => 5);
512+const handler = () => {};
513+process.on("SIGUSR1", handler);
514+try {
515+setPreRestartDeferralCheck(pendingCheck);
516+scheduleGatewaySigusr1Restart({ delayMs: 1_000, reason: "config.patch" });
517+const forced = scheduleGatewaySigusr1Restart({
518+delayMs: 1_000,
519+reason: "update.run",
520+skipDeferral: true,
521+});
522+523+expect(forced.coalesced).toBe(false);
524+525+await vi.advanceTimersByTimeAsync(1_000);
526+527+expect(pendingCheck).not.toHaveBeenCalled();
528+expect(emitSpy).toHaveBeenCalledWith("SIGUSR1");
529+expect(peekGatewaySigusr1RestartReason()).toBe("update.run");
530+} finally {
531+process.removeListener("SIGUSR1", handler);
532+}
533+});
534+535+it("bypasses an active restart deferral when a forced restart arrives", async () => {
536+const emitSpy = vi.spyOn(process, "emit");
537+const staleBeforeEmit = vi.fn(async () => {});
538+const handler = () => {};
539+process.on("SIGUSR1", handler);
540+try {
541+setPreRestartDeferralCheck(() => 5);
542+scheduleGatewaySigusr1Restart({
543+delayMs: 0,
544+reason: "config.patch",
545+emitHooks: { beforeEmit: staleBeforeEmit },
546+});
547+await vi.advanceTimersByTimeAsync(0);
548+expect(emitSpy).not.toHaveBeenCalledWith("SIGUSR1");
549+550+const forced = scheduleGatewaySigusr1Restart({
551+delayMs: 0,
552+reason: "update.run",
553+skipDeferral: true,
554+});
555+556+expect(forced.coalesced).toBe(false);
557+expect(emitSpy).toHaveBeenCalledWith("SIGUSR1");
558+expect(staleBeforeEmit).not.toHaveBeenCalled();
559+expect(peekGatewaySigusr1RestartReason()).toBe("update.run");
560+} finally {
561+process.removeListener("SIGUSR1", handler);
562+}
563+});
564+486565it("emits SIGUSR1 after the default deferral timeout while work is still pending", async () => {
487566const emitSpy = vi.spyOn(process, "emit");
488567const handler = () => {};
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。