Skip to content

test(torrent): make TorrentSwarmRedialTest wait on the swarm instead of fixed delays - #586

Merged
linroid merged 2 commits into
mainfrom
fix/torrent-redial-test-flake
Oct 18, 2026
Merged

linroid merged 2 commits into
mainfrom
fix/torrent-redial-test-flake

Conversation

@linroid

@linroid linroid commented Oct 17, 2026

Copy link
Copy Markdown
Owner

TorrentSwarmRedialTest failed intermittently on loaded runners (main JVM Tests, run 39045165577; PR #581 iOS Tests and Torrent filesystem macos-26, run 39048194471), always with "The swarm never dialed the peer again". The failures had two causes.

peerKeptOverOurDial_isDialedThereAgainUntilItIsBack: a race across two connections

The test served piece 0 over the connection the swarm dialed, then at once dialed the swarm itself. When the incoming connection claimed the peer before the swarm had read that piece, the outgoing worker's broughtPayload was still false. The kept connection then inherited no payload, so redial treated the endpoint as never delivering. It was given up after three refused dials (5, 20 and 50 s), all before the peer came back at 70 s.

Fix: the test reads the dialed wire until the swarm sends NOT_INTERESTED, which it sends only after verifying the piece, before it dials the swarm.

Reproduced: a 500 ms delay injected before outgoing workers count a piece made the old test fail; with the fix it passes.

droppedPeer_isGivenUpAfterTenDials: clock lag

The clock moves 60 s every 110 ms of real time. A loaded runner handles each refusal a step or more late, and retryAt counts from when the refusal is handled, so the tenth dial landed close to the fixed 40-minute mark. Finding the peer again at 40 minutes then fell within GIVEN_UP_MS of that last dial, and the swarm ignored it.

Fix: the test advances until the tenth dial (bounded at an hour), then ten more minutes. It still checks that exactly ten dials happened, so an eleventh, due five minutes after the tenth, would fail it. The peer is found again only after that.

Reproduced: 250 ms of lag injected into the swarm's result handling made the old test fail ("expected 10 but was 8"); the new one passes.

Other fixed waits

  • peerUpFiveMinutes_isDialedAgainAsAtFirst advances until the redial happens (within 30 s) instead of delay(300), advancing 5 s, delay(300).
  • lonelyStall_stillForgetsAPeerItGaveUpOn waits for the fourth dial on a clock that has stopped, instead of delay(300).
  • The per-test timeout goes from 30 s to 50 s (still under runTest's 60 s). A failing run on a slow runner reached 29 s.

No production code changes.

Verification

Every core was kept busy by a CPU-burning loop during both stress runs:

  • :library:torrent:jvmTest --tests …TorrentSwarmRedialTest: 20 of 20 runs passed.
  • :library:torrent:iosSimulatorArm64Test -PenableIosSimulatorTests=true: 8 of 8 runs passed.

…armRedialTest

peerKeptOverOurDial dialed the swarm before it had read piece 0 over our connection, so the replacing connection inherited no payload and the endpoint was given up after three dials. It now waits for the swarm's NOT_INTERESTED first.

droppedPeer_isGivenUpAfterTenDials advanced to a fixed 40 minutes; on a loaded runner each refusal is handled a step late, so the tenth dial came so late that finding the peer again at 40 minutes fell within five minutes of it and was ignored. It now advances until the tenth dial, then ten more minutes.

peerUpFiveMinutes and lonelyStall_stillForgetsAPeerItGaveUpOn wait for the dial count instead of fixed 300 ms sleeps, and the overall timeout is 50 s.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T17:30:55.513310Z 8d4527b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 2 048 files  ±0   2 076 suites  ±0   32m 36s ⏱️ - 1m 0s
13 716 tests ±0  13 452 ✅ ±0  264 💤 ±0  0 ❌ ±0 
16 707 runs  ±0  16 443 ✅ ±0  264 💤 ±0  0 ❌ ±0 

Results for commit cc3b686. ± Comparison against base commit 2462373.

♻️ This comment has been updated with latest results.

@linroid
linroid merged commit 51c4b05 into main Oct 18, 2026
14 checks passed
@linroid
linroid deleted the fix/torrent-redial-test-flake branch October 18, 2026 00:09
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