Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions tests/config/config-ownership-concurrent-record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ const modulePath = repoPath("src/lib/config-ownership.ts");
const BARRIER_MS = 20_000;
// Exit codes: 0 recorded, 2 not recorded, 3 refused by the uninstall tombstone, 1 anything else.
// With a gate, the child creates its file, announces it, and records only once the gate opens.
const childScript = (dir: string, rel: string, gate?: { ready: string; go: string }) => [
const childScript = (dir: string, rel: string, gate?: { ready: string; go: string }, createPath = true) => [
"import { existsSync, writeFileSync } from \"node:fs\";",
"import { ConfigUninstallInProgressError, recordOwnedConfigPath } from " + JSON.stringify(modulePath) + ";",
"const path = " + JSON.stringify(join(dir, rel)) + ";",
gate ? "writeFileSync(path, \"child\"); writeFileSync(" + JSON.stringify(gate.ready) + ", \"\");" : "",
gate && createPath ? "writeFileSync(path, \"child\");" : "",
gate ? "writeFileSync(" + JSON.stringify(gate.ready) + ", \"\");" : "",
gate ? "const until = Date.now() + " + BARRIER_MS + "; while (!existsSync(" + JSON.stringify(gate.go) + ") && Date.now() < until) Bun.sleepSync(5);" : "",
// A busy ownership lock fails fast; callers retry, and so does this child.
"let code = 1;",
Expand Down Expand Up @@ -405,13 +406,9 @@ describe("concurrent first registrations on an absent home (#8093)", () => {
const names = Array.from({ length: 6 }, (_, i) => "cold-" + i);
const signals = dirname(dir);
const go = join(signals, "go-cold");
const script = (rel: string) => [
"import { existsSync, writeFileSync } from \"node:fs\";",
"import { recordOwnedConfigPath } from " + JSON.stringify(modulePath) + ";",
"writeFileSync(" + JSON.stringify(join(signals, rel + ".ready")) + ", \"\");",
"const until = Date.now() + " + BARRIER_MS + "; while (!existsSync(" + JSON.stringify(go) + ") && Date.now() < until) Bun.sleepSync(2);",
"process.exit(recordOwnedConfigPath(" + JSON.stringify(dir) + ", " + JSON.stringify(join(dir, rel)) + ") ? 0 : 2);",
].join("\n");
// Use the same bounded busy-lock retry as other registration children, while
// leaving the home absent until the synchronized first registration starts.
const script = (rel: string) => childScript(dir, rel, { ready: join(signals, rel + ".ready"), go }, false);
Comment thread
luvs01 marked this conversation as resolved.
Resolved
const children = names.map(name => Bun.spawn([process.execPath, "-e", script(name)], { stderr: "inherit" }));
const deadline = Date.now() + BARRIER_MS;
while (Date.now() < deadline && !names.every(name => existsSync(join(signals, name + ".ready")))) await Bun.sleep(10);
Expand Down
Loading