Repository navigation
test(torrent): make TorrentSwarmRedialTest wait on the swarm instead of fixed delays - #586
Merged
Merged
Conversation
…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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TorrentSwarmRedialTestfailed 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 connectionsThe 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
broughtPayloadwas still false. The kept connection then inherited no payload, soredialtreated 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 lagThe clock moves 60 s every 110 ms of real time. A loaded runner handles each refusal a step or more late, and
retryAtcounts 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 withinGIVEN_UP_MSof 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_isDialedAgainAsAtFirstadvances until the redial happens (within 30 s) instead ofdelay(300), advancing 5 s,delay(300).lonelyStall_stillForgetsAPeerItGaveUpOnwaits for the fourth dial on a clock that has stopped, instead ofdelay(300).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.