Skip to content

test(time): use fake timers instead of real setTimeout waits - #2923

Open
nikolauspschuetz wants to merge 1 commit into
cucumber:mainfrom
nikolauspschuetz:test/time-fake-timers
Open

nikolauspschuetz wants to merge 1 commit into
cucumber:mainfrom
nikolauspschuetz:test/time-fake-timers

Conversation

@nikolauspschuetz

@nikolauspschuetz nikolauspschuetz commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🤔 What's changed?

time_spec.ts drove wrapPromiseWithTimeout() with real setTimeout timers, so the "does not time out" case raced a 10ms resolve against a 25ms timeout. Switched to @sinonjs/fake-timers, same as #2874.

⚡️ What's your motivation?

That 10ms-vs-25ms case can flake under CI load.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code — no, test-only
  • My change requires a change to the documentation
  • Users should know about my change — no, no CHANGELOG entry

This text was originally generated from a template, then edited by hand. You can modify the template here.

The wrapPromiseWithTimeout specs raced real setTimeout timers — an inner
promise resolving at 50/10ms against a 25ms timeout — so the "does not
time out" case (10ms vs 25ms) is a latent flake: under CI load the event
loop can fire the 25ms timeout before the 10ms resolve and reject a
promise that was supposed to succeed.

Drive the timers with @sinonjs/fake-timers via
FakeTimers.withGlobal(timeMethods) — the same pattern used in
stopwatch_spec.ts, test_case_runner_spec.ts and assemble_test_cases_spec.ts,
and wrapPromiseWithTimeout schedules its timeout through the shared
../time methods object, so faking that object controls it. The clock is
advanced with clock.tick(...), making the outcome of each race
deterministic regardless of real-world scheduling. Behaviour and
assertions are unchanged; the file no longer waits on the wall clock.

Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review September 3, 2026 19:00
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