mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 05:42:43 +00:00
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:
@@ -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 () => {
|
||||
|
||||
@@ -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);
|
||||
`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user