Skip to content

Commit edd4677

Browse files
committed
Widen watchdog probe stall windows for loaded parallel runs
300ms stall windows flake under the parallel load this runner enables. 1.5s keeps several ticks of scheduling headroom while a never-resetting timer still fires mid-run. Also documents the teardownDeadlineMs single-setter assumption.
1 parent 7eec056 commit edd4677

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎scripts/test-parallel.test.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ function processAlive(pid: number): boolean {
1515
}
1616

1717
// These probes are `bun -e` one-liners, so they never import project modules
18-
// and finish in milliseconds. Stall windows are tiny (300-500ms) to keep the
19-
// file fast while still exercising the watchdog's timing logic.
18+
// and finish in seconds. Stall windows are ~1.5s: under the `--parallel`
19+
// load this runner exists to enable, a delayed output tick can look like a
20+
// stall against a tighter window, so the window keeps several ticks of
21+
// scheduling headroom while a broken never-resetting timer still fires
22+
// mid-run (the tick test's total runtime exceeds the window).
23+
const TEST_STALL_MS = 1_500;
2024

2125
describe("runWithWatchdog", () => {
2226
test("passes through a successful run without retrying", async () => {
@@ -48,15 +52,15 @@ describe("runWithWatchdog", () => {
4852
});
4953

5054
test("output resets the stall timer", async () => {
51-
// Prints every 100ms for ~700ms against a 300ms stall window: a broken
52-
// timer that never reset would fire on the second tick.
55+
// Prints every 250ms for ~2.5s against a 1.5s stall window: a broken
56+
// timer that never reset would fire mid-run.
5357
const result = await runWithWatchdog({
5458
command: process.execPath,
5559
args: [
5660
"-e",
57-
"for (let i = 0; i < 7; i++) { console.log('tick', i); await new Promise(r => setTimeout(r, 100)); }",
61+
"for (let i = 0; i < 10; i++) { console.log('tick', i); await new Promise(r => setTimeout(r, 250)); }",
5862
],
59-
stallMs: 300,
63+
stallMs: TEST_STALL_MS,
6064
});
6165
expect(result.exitCode).toBe(0);
6266
expect(result.stalled).toBe(false);
@@ -79,7 +83,7 @@ describe("runWithWatchdog", () => {
7983
const result = await runWithWatchdog({
8084
command: process.execPath,
8185
args: ["-e", code],
82-
stallMs: 300,
86+
stallMs: TEST_STALL_MS,
8387
onStall: (attempt, max) => stalls.push([attempt, max]),
8488
});
8589
expect(result.exitCode).toBe(0);
@@ -93,7 +97,7 @@ describe("runWithWatchdog", () => {
9397
const result = await runWithWatchdog({
9498
command: process.execPath,
9599
args: ["-e", "setTimeout(() => {}, 30_000)"],
96-
stallMs: 300,
100+
stallMs: TEST_STALL_MS,
97101
attempts: 2,
98102
onStall: (attempt, max) => stalls.push([attempt, max]),
99103
});
@@ -117,7 +121,7 @@ describe("runWithWatchdog", () => {
117121
const result = await runWithWatchdog({
118122
command: process.execPath,
119123
args: ["-e", code],
120-
stallMs: 300,
124+
stallMs: TEST_STALL_MS,
121125
attempts: 1,
122126
});
123127
expect(result.exitCode).toBe(1);

‎src/index.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ export const RUNTIME_TEARDOWN_DEADLINE_MS = 2_000;
139139
// the bound so a deliberately never-settling dispose host doesn't pay the
140140
// full 2s of wall clock per test (same pattern as the tool watchdog's
141141
// salvageGraceMs override).
142+
// Single-setter assumption: this is one process-global read by both
143+
// installCrashHandlers and installSignalHandlers, so the last installer call
144+
// wins. Production never sets it; the only setter is the reap-fixture
145+
// subprocess (tests/fixtures/exec-shutdown-reap/simulate-reap.ts), which sets
146+
// it once per process before installing — never both installers with
147+
// different values in one process.
142148
let teardownDeadlineMs = RUNTIME_TEARDOWN_DEADLINE_MS;
143149

144150
export interface ProcessHandlerOptions {

0 commit comments

Comments
 (0)