From 5d51975c11d15c49c1a8bce87e5cc59c0d265942 Mon Sep 17 00:00:00 2001 From: Sean Larkin <3408176+TheLarkInn@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:35:33 +0000 Subject: [PATCH] Fix three daemon/client tests that flake on slow agents The Rush publish pipeline's "rush retest" step failed on these tests on slow agents: - rush-client-core "waits a whole backoff step...": a 3 s deadline left no room after a late helper exit. The deadline is now 8 s, and the upper bound is derived from the backoff schedule and the time that remained. - rush-cli-client "expired-preflight": a 100 ms budget could expire during connect, before the preflight was sent. The budget is now 2 s, and the fake daemon holds the preflight reply until that budget has passed. - rush-daemon launcher attestation tests: they spawn a Node.js probe but used Jest's 5 s default timeout. They now get 15 s, like their peers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 08766d06-fe09-43d1-b604-3b9f433d1785 --- .../src/test/GraphGenerationWire.test.ts | 13 +++++++------ ...ublish-daemon-flakes_2026-12-01-14-22.json | 11 +++++++++++ ...ublish-daemon-flakes_2026-12-01-14-22.json | 11 +++++++++++ ...ublish-daemon-flakes_2026-12-01-14-22.json | 11 +++++++++++ .../connectOrStartDaemonHelperExit.test.ts | 19 ++++++++++++++----- .../VersionSelectedDaemonLauncher.test.ts | 5 +++-- 6 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 common/changes/@rushstack/rush-cli-client/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json create mode 100644 common/changes/@rushstack/rush-client-core/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json create mode 100644 common/changes/@rushstack/rush-daemon/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json diff --git a/apps/rush-cli-client/src/test/GraphGenerationWire.test.ts b/apps/rush-cli-client/src/test/GraphGenerationWire.test.ts index e251e71101..6616974a8e 100644 --- a/apps/rush-cli-client/src/test/GraphGenerationWire.test.ts +++ b/apps/rush-cli-client/src/test/GraphGenerationWire.test.ts @@ -305,11 +305,12 @@ describe('generation-aware graph reference client', () => { return; } try { - if ( - request.argv[2] === 'status' && - (mode === 'remaining-budget' || mode === 'expired-preflight') - ) { + if (request.argv[2] === 'status' && mode === 'remaining-budget') { await delayAsync(200); + } else if (request.argv[2] === 'status' && mode === 'expired-preflight') { + // Answer only once the client's admission deadline has passed, however long it took to + // send this preflight. + await delayAsync(request.admission!.waitTimeoutMs! + 100); } await connection.sendFrameAsync({ kind: DaemonFrameType.event, @@ -367,7 +368,7 @@ describe('generation-aware graph reference client', () => { mode === 'no-wait' ? ['--no-wait'] : mode === 'expired-preflight' - ? ['--wait-timeout', '0.1'] + ? ['--wait-timeout', '2'] : ['timeout', 'remaining-budget', 'explicit'].includes(mode) ? ['--wait-timeout', '0.5'] : []; @@ -426,7 +427,7 @@ describe('generation-aware graph reference client', () => { : mode === 'default' || mode === 'cancel-preflight' ? 30000 : mode === 'expired-preflight' - ? 100 + ? 2000 : 500; expect(requests[0].admission!.waitTimeoutMs).toBeGreaterThan(0); expect(requests[0].admission!.waitTimeoutMs).toBeLessThanOrEqual(maximum); diff --git a/common/changes/@rushstack/rush-cli-client/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json b/common/changes/@rushstack/rush-cli-client/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json new file mode 100644 index 0000000000..18c23541b9 --- /dev/null +++ b/common/changes/@rushstack/rush-cli-client/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "", + "type": "none", + "packageName": "@rushstack/rush-cli-client" + } + ], + "packageName": "@rushstack/rush-cli-client", + "email": "3408176+TheLarkInn@users.noreply.github.com" +} diff --git a/common/changes/@rushstack/rush-client-core/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json b/common/changes/@rushstack/rush-client-core/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json new file mode 100644 index 0000000000..9d36067f66 --- /dev/null +++ b/common/changes/@rushstack/rush-client-core/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "", + "type": "none", + "packageName": "@rushstack/rush-client-core" + } + ], + "packageName": "@rushstack/rush-client-core", + "email": "3408176+TheLarkInn@users.noreply.github.com" +} diff --git a/common/changes/@rushstack/rush-daemon/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json b/common/changes/@rushstack/rush-daemon/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json new file mode 100644 index 0000000000..d5281834eb --- /dev/null +++ b/common/changes/@rushstack/rush-daemon/bot-fix-publish-daemon-flakes_2026-12-01-14-22.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "", + "type": "none", + "packageName": "@rushstack/rush-daemon" + } + ], + "packageName": "@rushstack/rush-daemon", + "email": "3408176+TheLarkInn@users.noreply.github.com" +} diff --git a/libraries/rush-client-core/src/test/connectOrStartDaemonHelperExit.test.ts b/libraries/rush-client-core/src/test/connectOrStartDaemonHelperExit.test.ts index 6493ee7f84..f5b4ed7b9d 100644 --- a/libraries/rush-client-core/src/test/connectOrStartDaemonHelperExit.test.ts +++ b/libraries/rush-client-core/src/test/connectOrStartDaemonHelperExit.test.ts @@ -207,24 +207,33 @@ describe('detached daemon startup while the startup helper runs', () => { // and exits. const { timeline, restore } = recordStartupTimeline(); try { + // A slow machine can take seconds to start the helper and daemon, so leave room for later attempts. await expect( connectOrStartDaemonAsync({ ...options, - startupTimeoutMs: 3000, + startupTimeoutMs: 8000, startCommand: { ...options.startCommand!, args: [...options.startCommand!.args, 'other'] } }) ).rejects.toThrow('Daemon startup timed out awaiting hello/ping readiness.'); + const timedOutAt: number = performance.now(); const { attempts, helperClosedAt } = timeline; expect(helperClosedAt).toBeDefined(); const afterExit: number[] = attempts.filter((attempt) => attempt >= helperClosedAt!); - // Only the first attempt after the exit comes early. Each later one waits a whole step, so fewer - // than 10 fit in the rest of the deadline. + // At most two attempts after the exit come early: one that checked the helper just before it exited, + // and the next. Each later one waits a whole step of at least 50, 100, 200, 400, then 500 ms, and the + // deadline may cut only the last step short. + let maximumAttempts: number = 3; + for (let step: number = 50, elapsed: number = step; elapsed <= timedOutAt - helperClosedAt!; ) { + maximumAttempts++; + step = Math.min(500, step * 2); + elapsed += step; + } expect(afterExit.length).toBeGreaterThan(1); - expect(afterExit.length).toBeLessThan(10); + expect(afterExit.length).toBeLessThanOrEqual(maximumAttempts); } finally { restore(); } - }, 15000); + }, 30000); it('stops at once when aborted while it waits for its startup helper', async () => { // The daemon waits before it listens, so this client sleeps between refused connection attempts. diff --git a/libraries/rush-daemon/src/test/VersionSelectedDaemonLauncher.test.ts b/libraries/rush-daemon/src/test/VersionSelectedDaemonLauncher.test.ts index 3e1b340369..6882402ef4 100644 --- a/libraries/rush-daemon/src/test/VersionSelectedDaemonLauncher.test.ts +++ b/libraries/rush-daemon/src/test/VersionSelectedDaemonLauncher.test.ts @@ -90,6 +90,7 @@ describe('version-selected daemon launcher', () => { } it('attests the actual bundled engine and protocol without changing the caller environment', async () => { + // Attestation loads the engine in a fresh Node.js process, which can take seconds on a busy machine. const originalRushLibPath: string | undefined = process.env._RUSH_LIB_PATH; const selected = await selectDaemonLauncherAsync(context, { allowInstall: false }); expect(selected.rushVersion).toBe(Rush.version); @@ -99,7 +100,7 @@ describe('version-selected daemon launcher', () => { ); expect(selected.startCommand.command).toBe(process.execPath); expect(process.env._RUSH_LIB_PATH).toBe(originalRushLibPath); - }); + }, 15000); it("starts the daemon without the starting client's request-scoped variables", () => { const command = getSelectedDaemonStartCommand(path.join(repoRoot, 'package.json'), { @@ -174,7 +175,7 @@ describe('version-selected daemon launcher', () => { ); expect(selected.rushVersion).toBe(Rush.version); expect(fs.readFileSync(path.join(repoRoot, 'rush.json'), 'utf8')).toBe(rushJson); - }); + }, 15000); it.each([false, true])( 'starts the attested engine through its real default APIs (preview: %s)',