Skip to content

test(desktop): stop the focus-resume test racing a fixed 10ms sleep - #6278

Open
mfethe1 wants to merge 1 commit into
block:mainfrom
mfethe1:fix/blur-test-race
Open

test(desktop): stop the focus-resume test racing a fixed 10ms sleep#6278
mfethe1 wants to merge 1 commit into
block:mainfrom
mfethe1:fix/blur-test-race

Conversation

@mfethe1

@mfethe1 mfethe1 commented Aug 19, 2026

Copy link
Copy Markdown

test(desktop): stop the focus-resume test racing a fixed 10ms sleep

focused polling pauses on blur and resumes after activation yields waited a
single setTimeout(…, 10) for the resume to land, then asserted the observed
sequence. The resume is a three-hop chain — scheduleAfterForegroundReady does
setTimeout(0)requestAnimationFramesetTimeout(0) — and jsdom fires
rAF on a ~16ms cadence, so 10ms could never reliably cover it. The test passed
on an idle machine and failed whenever the event loop was contended, which is
exactly what a full pnpm test run does.

It now polls until the resume is observed (2s ceiling) instead of guessing a
duration. The assertion is unchanged and just as strict: the same
assert.deepEqual(observed, [1_000, false, 1_000]) still runs, so a resume that
never fires still fails, with the same diff.

Measured on x86_64-pc-windows-msvc, running the file 12x with six busy loops
saturating the CPU:

  • before: 8 passed, 4 failed
  • after: 12 passed, 0 failed

Full desktop suite with the fix: pnpm test 5037 passed, 0 failed (it had been
reporting 5036/1 on this test); pnpm check exit 0.

`focused polling pauses on blur and resumes after activation yields` waited a
single `setTimeout(…, 10)` for the resume to land, then asserted the observed
sequence. The resume is a three-hop chain — `scheduleAfterForegroundReady` does
`setTimeout(0)` → `requestAnimationFrame` → `setTimeout(0)` — and jsdom fires
rAF on a ~16ms cadence, so 10ms could never reliably cover it. The test passed
on an idle machine and failed whenever the event loop was contended, which is
exactly what a full `pnpm test` run does.

It now polls until the resume is observed (2s ceiling) instead of guessing a
duration. The assertion is unchanged and just as strict: the same
`assert.deepEqual(observed, [1_000, false, 1_000])` still runs, so a resume that
never fires still fails, with the same diff.

Measured on x86_64-pc-windows-msvc, running the file 12x with six busy loops
saturating the CPU:

- before: 8 passed, 4 failed
- after: 12 passed, 0 failed

Full desktop suite with the fix: `pnpm test` 5037 passed, 0 failed (it had been
reporting 5036/1 on this test); `pnpm check` exit 0.

Signed-off-by: Michael Feth <michael@jira-flow.com>
@mfethe1
mfethe1 requested a review from a team as a code owner August 19, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant