Skip to content

flaky: key-set-fetcher.test.ts waits 50 ms of real time for a request to reach its server #1981

Done

Description

@V3RON

src/ports/key-set-fetcher.test.ts:58-59 sleeps 50 ms and then asserts expect(received).toBe(true). On a loaded macOS host (15-minute load average 52, read five minutes later) the request had not arrived by then:

AssertionError: expected false to be true // Object.is equality   src/ports/key-set-fetcher.test.ts:59:22

Seen once, in a run of all of src/ports; the file passed in the next run. Found while triaging #1979.

Written by an agent.

Activity

  1. added
    bug:new
    flaky-test
    on Nov 30, 2026
  2. self-assigned this
    on Nov 30, 2026
  3. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Seen on: the reporter's test output (a loaded macOS host). Not reproduced unmodified: 25 of 25 runs passed here at load average 42 to 53 on 12 cores.

    The bug is in the test; the fetcher is correct. On bug/1981-repro, src/ports/key-set-fetcher.test.ts, "ends a request its server receives late and never answers when its signal aborts": the existing test, whose server now stops the process for 200 ms when the connection arrives, as a loaded host does. It fails every run (10 of 10) with the reported assertion:

    pnpm exec vitest run --project unit src/ports/key-set-fetcher.test.ts
    
    AssertionError: expected false to be true // Object.is equality
     ❯ src/ports/key-set-fetcher.test.ts:64:22   (line 59 on main)
    

    Root cause

    Defect in the test. src/ports/key-set-fetcher.test.ts:58 on main waits a fixed 50 ms for the request to reach the server, and line 59 asserts that it did. The connection and the request need several turns of the event loop the test shares with its server. When the process does not run for 50 ms in between, the timer fires first. Testing rule 5 keeps such a real-time bound out of unit tests. The 1 s wait at line 62 is not a second race: with it replaced by microtasks alone, the test passes, so abort() settles the fetch before any timer can fire.

    Simplest fix

    Wait for the request itself. A fetch that fails early still ends the wait, and line 59 then names the failure.

    import { once } from "node:events";
    // replaces the 50 ms wait
    await Promise.race([once(server as Server, "request"), settled]);
    fix:       3 passed (3); vitest run --project unit src/ports → 438 passed | 11 skipped; pnpm typecheck clean
    mutation:  fetch without the signal   → expected undefined to be 'AbortError'
    mutation:  throws before sending      → expected false to be true
    

    Alternatives rejected

    • A longer wait: still a race with host load.
    • Drop line 59: an abort before the connection would then pass too.

    Risk

    • A fetch that neither sends nor settles now fails by vitest's 20 s timeout, not on line 59.
    • The 200 ms stop, kept as the regression case, adds 200 ms to the file.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Side findings

    Written by an agent.

  4. removed their assignment
    on Nov 30, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 30, 2026
  6. self-assigned this
    on Nov 30, 2026
  7. V3RON commented on Nov 30, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1983 (#1981)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  8. added a commit that references this issue on Nov 30, 2026
    0ac0d06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyfast-trackflaky-test

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions