Skip to content

export: make the cancelled-resume test deterministic - #4

Merged
selul merged 1 commit into
mainfrom
claude/deflake-resume-test
Nov 10, 2026
Merged

selul merged 1 commit into
mainfrom
claude/deflake-resume-test

Conversation

@selul

@selul selul commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

TestRunResumesDownloadsCancelledMidway failed the v0.4.0 release run and passed on a re-run. The test read the fake server's log before the fake had filed the cancelled downloads, so it checked those downloads as resumed ones.

Note

The flaky test was added in 54e0b1c on version v0.2.0 (2026-11-04).

What changed

  • Fake server (internal/testserver) — counts the requests it is handling. The new WaitIdle waits until none are left, so Events holds every request made so far.

  • Cancelled-resume test: log boundary — calls WaitIdle before it counts the first run's downloads. Before: a first-run download filed late was checked as a resumed one, with no Range. After: only the second run's downloads are checked.

  • Cancelled-resume test: cancel point — cancels the first run when both partial files hold the 30 and 40 bytes sent before the stalls. Before: it cancelled 100 ms after the second download arrived.

  • Cancelled-resume test: resume check — the resumed run must make exactly two downloads, and each must carry the Range of its own partial file. Before: any download with bytes=30- or bytes=40- passed.

Note

The fake files a request when its handler ends. A stalled download ends only when the fake sees that the client closed the connection, and that can happen after Run returned. The failing events in the release log (Start:3, empty Range) are the first run's downloads. The 100 ms cancel did not fail in local stress runs, but it also depended on the scheduler. Production code does not change: the client resumed correctly in every run.

QA

  1. On main, run the test under CPU stress:

    GOMAXPROCS=1 go test -race -count=100 -cpu 1,2,4 -run TestRunResumesDownloadsCancelledMidway ./internal/export

    Expect: some runs fail with resume without the right range.

  2. Check out this branch. Run the same command with -count=500.

    Expect: ok for internal/export, with no failure.

🤖 Generated with Claude Code

TestRunResumesDownloadsCancelledMidway failed the v0.4.0 release run
with "resume without the right range" for both archives. The failing
downloads were those of the cancelled first run, not the resumed ones:

- The fake files a request when its handler ends, and a stalled
  download ends only once the fake notices the client left. That can
  be after Run returned, so the test's count of earlier downloads was
  short and their Range-less events were checked as resumed ones. The
  fake now counts the requests it is handling; WaitIdle waits for zero,
  and the test calls it before it counts.
- The run was cancelled 100 ms after the second download arrived,
  assuming both partial files had their bytes by then. It is now
  cancelled once both partial files hold the 30 and 40 bytes sent
  before the stalls.

The resumed run must now make exactly two downloads, each with the
Range of its own partial file. Production code is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@selul
selul merged commit 29d8f04 into main Nov 10, 2026
12 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