Skip to content

Commit bec8ecd

Browse files
author
engineer
committed
fix: use readiness signal instead of sleep in SIGTERM test to avoid race condition
1 parent 66ce697 commit bec8ecd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/opencode/test/memory/cleanup.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,19 @@ describe("memory: cleanup", () => {
8383
'process.on("SIGTERM", () => graceful("SIGTERM"));',
8484
'process.on("SIGINT", () => graceful("SIGINT"));',
8585
'process.on("SIGHUP", () => graceful("SIGHUP"));',
86+
// Signal readiness by writing to stdout
87+
'process.stdout.write("ready\\n");',
8688
"setTimeout(() => process.exit(1), 10000);",
8789
].join("\n"),
8890
)
8991

9092
const proc = Bun.spawn(["bun", "run", script], { stdio: ["ignore", "pipe", "pipe"] })
9193

92-
// Give it time to register handlers
93-
await Bun.sleep(500)
94+
// Wait for the script to signal it has registered handlers
95+
const reader = proc.stdout.getReader()
96+
const { value } = await reader.read()
97+
const output = new TextDecoder().decode(value)
98+
expect(output.trim()).toBe("ready")
9499

95100
// Send SIGTERM (signal 15)
96101
proc.kill(15)

0 commit comments

Comments
 (0)