Skip to content

test(mac): control answer order in the coalescing-fetch invalidation test - #143

Merged
raiseCatError merged 1 commit into
devfrom
fix/coalescing-fetch-test-order
Nov 3, 2026
Merged

raiseCatError merged 1 commit into
devfrom
fix/coalescing-fetch-test-order

Conversation

@raiseCatError

Copy link
Copy Markdown
Owner

CoalescingFetchTests.testAnInvalidationDuringARequestWaitsForTheNextOne failed on #141's Mac job (run 41663143761): XCTAssertEqual failed: ("2") is not equal to ("1") at line 61. #141 only edits a workflow, so the failure is unrelated to it.

Root cause: an ordering assumption in the test, not an app bug

  • The stand-in service numbers answers by the order requests start, and the test slept 50 ms and relied on request 1 also answering first.
  • On a stalled runner (the test took 2.4 s instead of ~0.25 s), request 2 answered first. CoalescingFetch then correctly served both waiters from request 2, a request started after the invalidation, so first == 2. The late caller still got 2, and only 2 requests were sent.
  • Reproduced with the unchanged code and test body in a standalone build: 1 of about 2,000 runs, on a cold first launch, with exactly first=2 late=2 calls=2. A gated service that releases request 2 first gives the same result every time.
  • Same class as the earlier timing failures in this file (testNoMoreThanTwoRequestsAreOut, testStartedAfterNowGetsANewRequestSharedByLateCallers).

Change (test only)

  • A GatedService stand-in answers each request only when the test releases it, so the order is fixed by the test, not by the scheduler. Its only waits are condition polls ("request n is out"), not timing assumptions.
  • The original test keeps every assertion, with requests answering in order.
  • New …WhenAnswersArriveOutOfOrder: request 2 answers first. Both callers get 2, the late caller never gets the stale answer, and 2 requests are sent.
  • No app code, assertion or timeout is loosened, and no test is skipped.

Checked locally (Xcode builds blocked by low internal disk; the real test file was compiled with swiftc against XCTest):

  • All 12 CoalescingFetchTests pass.
  • The two changed tests ran 1,600 times with no failures (1,000 idle, 600 under full CPU load).
  • A mutant that serves the stale answer to every waiter fails the test.

The mac job here is the first full Xcode run of the change.

🤖 Generated with Claude Code

…test

The test assumed the two requests answer in the order they start. On a
stalled runner the second answered first (CI run 41663143761), so the early
caller correctly took the newer answer and the assertion failed. A gated
stand-in now fixes the order, and a second test covers answers arriving out
of order; every original assertion is kept.

Co-Authored-By: Claude <noreply@anthropic.com>
@raiseCatError
raiseCatError marked this pull request as ready for review November 3, 2026 17:00
@raiseCatError
raiseCatError merged commit 0de7932 into dev Nov 3, 2026
7 checks passed
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