fix(test): remove all setTimeout from inspector test fixtures

Replace timer-based process exits with parent-driven termination. Wait
for --inspect banner before sending SIGUSR1 in the ignored-signal test
to avoid killing before stderr is flushed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alistair Smith
2026-02-10 15:34:04 -08:00
parent bf15eb7955
commit 4e26dbe304
2 changed files with 21 additions and 11 deletions

View File

@@ -348,9 +348,8 @@ SIGNAL_3
fs.writeFileSync(path.join(process.cwd(), "pid"), String(process.pid));
console.log("READY");
// Keep process alive briefly then exit
setInterval(() => {}, 100);
setTimeout(() => process.exit(0), 2000);
// Keep process alive until parent kills it
setInterval(() => {}, 1000);
`,
});
@@ -375,16 +374,28 @@ SIGNAL_3
const pid = parseInt(await Bun.file(join(String(dir), "pid")).text(), 10);
// Wait for the --inspect banner to appear before sending SIGUSR1
const stderrReader = proc.stderr.getReader();
let stderr = await readStderrUntil(stderrReader, hasBanner);
// Send SIGUSR1 - should be ignored since RuntimeInspector is not installed
process.kill(pid, "SIGUSR1");
const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]);
// Kill and collect remaining stderr — parent drives termination
proc.kill();
const stderrDecoder = new TextDecoder();
while (true) {
const { value, done } = await stderrReader.read();
if (done) break;
stderr += stderrDecoder.decode(value, { stream: true });
}
stderrReader.releaseLock();
await proc.exited;
// Should only see one "Bun Inspector" banner (from --inspect flag, not from SIGUSR1)
// The banner has two occurrences of "Bun Inspector" (header and footer)
const matches = stderr.match(/Bun Inspector/g);
expect(matches?.length ?? 0).toBe(2);
expect(exitCode).toBe(0);
});
test("SIGUSR1 is ignored when started with --inspect-wait", async () => {

View File

@@ -161,8 +161,7 @@ describe.skipIf(!isWindows)("Runtime inspector Windows file mapping", () => {
fs.writeFileSync(path.join(process.cwd(), "pid"), String(process.pid));
console.log("READY");
// Keep process alive briefly then exit
setTimeout(() => process.exit(0), 2000);
// Keep process alive until parent kills it
setInterval(() => {}, 1000);
`,
});
@@ -211,16 +210,16 @@ describe.skipIf(!isWindows)("Runtime inspector Windows file mapping", () => {
});
await debug2.exited;
// Collect any remaining stderr and wait for process to exit
// Kill and collect remaining stderr — parent drives termination
targetProc.kill();
stderrReader.releaseLock();
const remainingStderr = await targetProc.stderr.text();
stderr += remainingStderr;
const exitCode = await targetProc.exited;
await targetProc.exited;
// Should only see one "Bun Inspector" banner (two occurrences of the text, for header and footer)
const matches = stderr.match(/Bun Inspector/g);
expect(matches?.length ?? 0).toBe(2);
expect(exitCode).toBe(0);
});
test("multiple Windows processes can have inspectors sequentially", async () => {
@@ -236,7 +235,7 @@ describe.skipIf(!isWindows)("Runtime inspector Windows file mapping", () => {
fs.writeFileSync(path.join(process.cwd(), "pid-" + id), String(process.pid));
console.log("READY-" + id);
setTimeout(() => process.exit(0), 5000);
// Keep process alive until parent kills it
setInterval(() => {}, 1000);
`,
});