Skip to content

Commit aad93dd

Browse files
Gustav-SimonssonTheGreatAxios
authored andcommitted
perf(tests): trim remaining dominant waits from the slowest test files
1 parent b3d0304 commit aad93dd

11 files changed

Lines changed: 310 additions & 302 deletions

‎scripts/ci-timings.json‎

Lines changed: 268 additions & 268 deletions
Large diffs are not rendered by default.

‎scripts/test-parallel.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ 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 seconds. The tick test keeps a ~0.7s stall window: under the
18+
// and finish in seconds. The tick test keeps a ~0.5s stall window: under the
1919
// `--parallel` load this runner exists to enable, a delayed output tick can
2020
// look like a stall against a tighter window, so the window keeps several
2121
// ticks of scheduling headroom while a broken never-resetting timer still
2222
// fires mid-run (the tick test's total runtime exceeds the window). The
2323
// remaining tests drive children that never emit output, so their stall is
2424
// declared deterministically on the watchdog's first tick; they use a short
2525
// window so the suite does not pay the tick test's headroom in wall clock.
26-
const TEST_STALL_MS = 700;
26+
const TEST_STALL_MS = 500;
2727
const SILENT_CHILD_STALL_MS = 250;
2828

2929
describe("runWithWatchdog", () => {
@@ -56,13 +56,13 @@ describe("runWithWatchdog", () => {
5656
});
5757

5858
test("output resets the stall timer", async () => {
59-
// Prints every 120ms for ~1s against a 0.7s stall window: a broken
59+
// Prints every 80ms for ~0.7s against a 0.5s stall window: a broken
6060
// timer that never reset would fire mid-run.
6161
const result = await runWithWatchdog({
6262
command: process.execPath,
6363
args: [
6464
"-e",
65-
"for (let i = 0; i < 8; i++) { console.log('tick', i); await new Promise(r => setTimeout(r, 120)); }",
65+
"for (let i = 0; i < 8; i++) { console.log('tick', i); await new Promise(r => setTimeout(r, 80)); }",
6666
],
6767
stallMs: TEST_STALL_MS,
6868
});
@@ -104,7 +104,7 @@ describe("runWithWatchdog", () => {
104104
command: process.execPath,
105105
args: [
106106
"-e",
107-
'process.on("SIGTERM", () => {}); setTimeout(() => process.exit(3), 400);',
107+
'process.on("SIGTERM", () => {}); setTimeout(() => process.exit(3), 300);',
108108
],
109109
stallMs: SILENT_CHILD_STALL_MS,
110110
onStall: () => {

‎src/agent/background-shell-tool.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("background shell through the agent toolset", () => {
4444
{
4545
id: "bg-start",
4646
name: "run_shell",
47-
arguments: { command: "sleep 0.4; echo bg-done", background: true },
47+
arguments: { command: "sleep 0.2; echo bg-done", background: true },
4848
},
4949
new AbortController().signal,
5050
);

‎src/plugins/shell-guard-plugin.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("runGuardedShell", () => {
5757
const feed = createShellOutputFeed();
5858
let finished = false;
5959
const running = runGuardedShell(
60-
{ command: "echo first; sleep 0.02; echo second; sleep 0.2" },
60+
{ command: "echo first; sleep 0.02; echo second; sleep 0.15" },
6161
neverAbort(),
6262
undefined,
6363
undefined,
@@ -85,7 +85,7 @@ describe("runGuardedShell", () => {
8585
test("omitted timeout does not arm a timer", async () => {
8686
const start = Date.now();
8787
const { exitCode, timedOut, output } = await runGuardedShell(
88-
{ command: "sleep 0.1; echo done" },
88+
{ command: "sleep 0.05; echo done" },
8989
neverAbort(),
9090
);
9191
expect(timedOut).toBe(false);
@@ -180,7 +180,7 @@ describe("runGuardedShell", () => {
180180
if (process.platform === "win32") return;
181181
const token = `ic_guard_orphan_${randomUUID()}`;
182182
const cmd = `bash -c 'IC_GUARD_TAG=${token} sleep 600 & IC_GUARD_TAG=${token} exec sleep 600'`;
183-
await runGuardedShell({ command: cmd, timeout: 250 }, neverAbort());
183+
await runGuardedShell({ command: cmd, timeout: 150 }, neverAbort());
184184
await waitUntilGone(token);
185185
});
186186

@@ -479,12 +479,12 @@ describe("background run_shell (shellGuardPlugin)", () => {
479479
id: "fg3",
480480
name: "run_shell",
481481
arguments: {
482-
// Fifteen lines ~10 ms apart: far more chunk arrivals than one
482+
// Fifteen lines ~5 ms apart: far more chunk arrivals than one
483483
// cadence window per 100 ms can allow. Without the Date.now() gate
484484
// in emitPendingOutput every arrival emits (~16 emissions) and this
485485
// ceiling fails — the assertion is what pins the cadence.
486486
command:
487-
"i=1; while [ $i -le 15 ]; do echo line$i; sleep 0.01; i=$((i+1)); done",
487+
"i=1; while [ $i -le 15 ]; do echo line$i; sleep 0.005; i=$((i+1)); done",
488488
},
489489
},
490490
neverAbort(),
@@ -1153,7 +1153,7 @@ describe("shellGuardPlugin", () => {
11531153

11541154
await first;
11551155
await Promise.race([queued, new Promise((r) => setTimeout(r, 250))]);
1156-
await new Promise((r) => setTimeout(r, 120));
1156+
await new Promise((r) => setTimeout(r, 80));
11571157

11581158
const leftover1 =
11591159
spawnSync("pgrep", ["-f", token1], {

‎src/shell/background-shell.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("background shell registry", () => {
2525
test("start returns a handle immediately while the process runs", async () => {
2626
const registry = createBackgroundShellRegistry();
2727
const started = registry.start({
28-
command: "sleep 0.2; echo done",
28+
command: "sleep 0.1; echo done",
2929
cwd: tmpCwd,
3030
});
3131
if ("error" in started) throw new Error(started.error);

‎src/tui/product-host.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ describe("mountProductHost", () => {
267267

268268
test("setChrome with running agents paints an agents panel clock", async () => {
269269
const now = Date.now();
270-
// Start 500ms before the minute boundary: the rollover assertion stays
270+
// Start 300ms before the minute boundary: the rollover assertion stays
271271
// identical while the boundary wait (up to a full minute from a 59:00
272-
// start) shrinks to at most ~0.5s of wall clock, with plenty of margin
272+
// start) shrinks to at most ~0.3s of wall clock, with plenty of margin
273273
// left for the mount + first capture to still see 0:59.
274274
const { host, renderOnce, captureCharFrame } = await mountHeadless({
275275
chrome: {
@@ -279,7 +279,7 @@ describe("mountProductHost", () => {
279279
currentToolStartedAt: null,
280280
description: "map callers",
281281
status: "running",
282-
startedAt: now - 59_500,
282+
startedAt: now - 59_700,
283283
lastActivityAt: now,
284284
},
285285
],
@@ -1017,7 +1017,7 @@ describe("flat type-to-filter model picker", () => {
10171017
await harness.renderOnce();
10181018
expect(host.shell.overlayKind).toBe("add_provider");
10191019
harness.pressKey("Escape");
1020-
await new Promise((r) => setTimeout(r, 60));
1020+
await new Promise((r) => setTimeout(r, 30));
10211021
await harness.renderOnce();
10221022
expect(host.shell.overlayKind).toBe("model_picker");
10231023
expect(host.shell.overlayItems).toEqual(modelItems);
@@ -1040,7 +1040,7 @@ describe("flat type-to-filter model picker", () => {
10401040
await harness.renderOnce();
10411041
expect(host.shell.overlayKind).toBe("add_provider");
10421042
harness.pressKey("Escape");
1043-
await new Promise((r) => setTimeout(r, 60));
1043+
await new Promise((r) => setTimeout(r, 30));
10441044
await harness.renderOnce();
10451045
expect(host.shell.overlayKind).not.toBe("model_picker");
10461046
expect(host.shell.overlayKind).toBeNull();
@@ -1078,7 +1078,7 @@ describe("flat type-to-filter model picker", () => {
10781078
await harness.renderOnce();
10791079
expect(host.shell.overlayKind).toBe("add_provider");
10801080
harness.pressKey("Escape");
1081-
await new Promise((r) => setTimeout(r, 60));
1081+
await new Promise((r) => setTimeout(r, 30));
10821082
await harness.renderOnce();
10831083
expect(host.shell.overlayKind).toBeNull();
10841084
} finally {

‎src/tui/request-approval.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("createGateRequestApproval", () => {
6464
});
6565
const pending = requestApproval(request);
6666
// Longer than the budget — frozen while the prompt is open.
67-
await new Promise((r) => setTimeout(r, 120));
67+
await new Promise((r) => setTimeout(r, 90));
6868
expect(getToolApprovalBudget()?.signal.aborted).toBe(false);
6969
captured?.resolve({ allow: true });
7070
const outcome = await pending;
@@ -179,7 +179,7 @@ describe("attachApprovalBudget", () => {
179179
);
180180
// Longer than the budget — frozen while the question is pending,
181181
// exactly like the permission gate's budget pause.
182-
await new Promise((r) => setTimeout(r, 120));
182+
await new Promise((r) => setTimeout(r, 90));
183183
expect(getToolApprovalBudget()?.signal.aborted).toBe(false);
184184
finish("answered");
185185
finish("answered again");

‎tests/fixtures/rawmode-sigint/probe.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ process.on("SIGINT", () => {
99
process.exit(0);
1010
});
1111
process.stdin.resume();
12+
// READY tells the driver the raw-mode handlers are installed, so it can send
13+
// the keypress without a fixed boot sleep.
14+
process.stdout.write("READY\n");
1215
process.stdin.on("data", (chunk: Buffer) => {
13-
if (chunk.includes(0x03)) process.stdout.write("GOT_CTRL_C_BYTE\n");
16+
if (!chunk.includes(0x03)) return;
17+
process.stdout.write("GOT_CTRL_C_BYTE\n");
18+
// A SIGINT, if the kernel delivered one, would arrive synchronously with
19+
// the keypress, so a short grace counted from the byte still proves none is
20+
// delivered without paying a fixed 3s (or an 800ms boot-independent wait)
21+
// in wall clock.
22+
setTimeout(() => {
23+
process.stdout.write("NO_SIGINT_ON_CTRL_C\n");
24+
process.exit(0);
25+
}, 300);
1426
});
15-
// A SIGINT, if the kernel delivered one, would arrive synchronously with the
16-
// keypress, so a short grace after GOT_CTRL_C_BYTE still proves none is
17-
// delivered without paying a fixed 3s in wall clock.
18-
setTimeout(() => {
19-
process.stdout.write("NO_SIGINT_ON_CTRL_C\n");
20-
process.exit(0);
21-
}, 800);

‎tests/fixtures/rawmode-sigint/pty_probe.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ def main() -> int:
1616
os.execvp("bun", ["bun", "run", probe_path])
1717
os._exit(127)
1818

19-
time.sleep(0.4)
20-
os.write(fd, b"\x03")
21-
2219
out = b""
2320
deadline = time.time() + 2.5
21+
sent_ctrl_c = False
2422
while time.time() < deadline:
2523
ready, _, _ = select.select([fd], [], [], 0.5)
2624
if fd not in ready:
@@ -32,6 +30,11 @@ def main() -> int:
3230
if not chunk:
3331
break
3432
out += chunk
33+
# Send the keypress only once raw mode is installed (no fixed boot
34+
# sleep); the probe's grace window then counts from the keypress.
35+
if not sent_ctrl_c and b"READY" in out:
36+
os.write(fd, b"\x03")
37+
sent_ctrl_c = True
3538
if b"NO_SIGINT_ON_CTRL_C" in out or b"GOT_SIGINT" in out:
3639
break
3740

‎tests/unit/telemetry-toggle.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ test("opting out discards events captured before the toggle instead of sending t
172172
expect(sends).toBe(0);
173173

174174
handler(false);
175-
await new Promise((resolve) => setTimeout(resolve, 150));
175+
await new Promise((resolve) => setTimeout(resolve, 60));
176176
expect(getInstance().enabled).toBe(false);
177177
expect(sends).toBe(0);
178178
});

0 commit comments

Comments
 (0)