Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
70 lines
2.5 KiB
JavaScript
70 lines
2.5 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
const test = require("node:test");
|
|
|
|
const {
|
|
registerPluginShutdown,
|
|
resetPluginShutdownForTests,
|
|
runPluginShutdown,
|
|
} = require("./shutdownCoordinator.cjs");
|
|
|
|
test("plugin shutdown is idempotent and completes before its quit deadline", async (context) => {
|
|
context.after(resetPluginShutdownForTests);
|
|
let calls = 0;
|
|
registerPluginShutdown(async () => { calls += 1; });
|
|
const [first, second] = await Promise.all([runPluginShutdown(), runPluginShutdown()]);
|
|
assert.deepEqual(first, { timedOut: false });
|
|
assert.deepEqual(second, { timedOut: false });
|
|
assert.equal(calls, 1);
|
|
});
|
|
|
|
test("plugin shutdown fails open after the bounded quit deadline", async (context) => {
|
|
context.after(resetPluginShutdownForTests);
|
|
registerPluginShutdown(async () => new Promise(() => {}));
|
|
assert.deepEqual(await runPluginShutdown({ timeoutMs: 5 }), { timedOut: true });
|
|
});
|
|
|
|
test("app shutdown waits for every registered cleanup handler", async (context) => {
|
|
context.after(resetPluginShutdownForTests);
|
|
const calls = [];
|
|
let releasePortForwardCleanup;
|
|
const portForwardCleanup = new Promise((resolve) => { releasePortForwardCleanup = resolve; });
|
|
registerPluginShutdown(async () => { calls.push("plugins"); });
|
|
registerPluginShutdown(async () => {
|
|
await portForwardCleanup;
|
|
calls.push("port-forwards");
|
|
});
|
|
|
|
let settled = false;
|
|
const shutdown = runPluginShutdown({ timeoutMs: 1_000 }).then((result) => {
|
|
settled = true;
|
|
return result;
|
|
});
|
|
await new Promise((resolve) => setImmediate(resolve));
|
|
assert.equal(settled, false);
|
|
assert.deepEqual(calls, ["plugins"]);
|
|
|
|
releasePortForwardCleanup();
|
|
assert.deepEqual(await shutdown, { timedOut: false });
|
|
assert.deepEqual(calls, ["plugins", "port-forwards"]);
|
|
});
|
|
|
|
test("one failed cleanup does not let app shutdown abandon other handlers", async (context) => {
|
|
context.after(resetPluginShutdownForTests);
|
|
let releaseRemainingCleanup;
|
|
const remainingCleanup = new Promise((resolve) => { releaseRemainingCleanup = resolve; });
|
|
registerPluginShutdown(async () => { throw new Error("plugin cleanup failed"); });
|
|
registerPluginShutdown(async () => remainingCleanup);
|
|
|
|
let settled = false;
|
|
const shutdown = runPluginShutdown({ timeoutMs: 1_000 }).finally(() => {
|
|
settled = true;
|
|
});
|
|
await new Promise((resolve) => setImmediate(resolve));
|
|
assert.equal(settled, false, "failure must not abandon another live cleanup");
|
|
|
|
releaseRemainingCleanup();
|
|
await assert.rejects(shutdown, /plugin cleanup failed/);
|
|
});
|