Repository navigation
test(torrent): check web seed stalls at fixed times, after the peers they count - #594
Merged
Merged
Conversation
…they count peerReconnectingAfterARelaunch_clearsWhatWasMissingOnlyWithThosePieces failed on the iOS simulator in CI: "Expected <CHOKED>, actual <MISSING_PIECES>" once the peer holding stale.bin connected. The swarm counts a peer as connected right after its handshake, but takes its bitfield in only with the next message it reads. The test stepped the clock a second every 200 ms and took the first stall that counted two peers, which a check between those two steps reports with stale.bin still missing. Delaying the bitfield in the swarm by a second makes the old test fail the same way every time. Stepping the clock on real time also let it run past the stall's thresholds on a slow runner: from 100 s it reaches the 120 s relaunch after 4 s of connecting, so the seed would start again before the test made it hold its request. Both stall tests that stepped the clock in a loop now move it only to fixed times, and wait for the check at each time, which its stall's seconds tell apart. Before a check they wait for what it should see: the swarm's bitfield, which it sends once it counts the peer; its INTERESTED, sent once it took in the bitfield of the peer holding stale.bin; and the peer's buffers coming back, which the swarm frees once it no longer counts a peer that left. The checks also assert the peer counts the old loops waited for.
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.
Problem
TorrentWebSeedTest.peerReconnectingAfterARelaunch_clearsWhatWasMissingOnlyWithThosePiecesfailed on the iOS simulator in CI on #590 (run 39082781513), while every JVM and Android job passed on the same commit. The iOS test report gives the assertion:Expected <CHOKED>, actual <MISSING_PIECES>at line 890, the check right after the peer holdingstale.binconnects.The swarm counts a peer as connected right after its handshake (
publishContact), but takes in its bitfield only when it reads the peer's next message (scheduler.availability). The test'sawaitStallstepped the clock a second every 200 ms of real time and returned the first stall counting two peers. A check that ran between those two steps saw two peers withstale.binstill unheld. I confirmed this by delaying the bitfield handoff inTorrentSwarmby a second: the old test then fails with the same assertion every time.Stepping the clock on real time also exposed the tests to the watchdog's thresholds. From 100 s, the clock hits the 120 s web seed relaunch after 4 s of connecting (6 s in
deadRelaunchedSeed_…, which stepped every 300 ms). The seed would then start again before the test made its mirror hold the request.Fix
Test-only. The two stall tests that stepped the clock in a loop now move it only to fixed times through
checkAt(time), which waits for that check's stall: since the stall lasts from the start,seconds == time / 1000picks out that check. Before each check, the tests wait for what it should see:INTERESTEDto the peer holdingstale.bin, sent once that peer's bitfield is in the scheduler (aspeerLackingAPiece_…already does);The checks also assert the peer counts the old loops used to wait for. In
peerReconnecting…the clock now moves 100 → 101 → 130 → 131 → 132 → 133 s.No production change: counting a peer before its bitfield arrives is expected, and the next check (a second later) is correct.
Testing
./gradlew :library:torrent:jvmTest --tests '*TorrentWebSeedTest*': 40/40, then 5 more times with--rerunwhile every core ran a busy loop (40/40 each), and once more on the final tree.peerReconnecting…fails at line 890 withexpected:<CHOKED> but was:<MISSING_PIECES>../gradlew :library:torrent:compileTestKotlinIosSimulatorArm64passes../gradlew :library:torrent:iosSimulatorArm64Test -PenableIosSimulatorTests=true --tests '*TorrentWebSeedTest*': 40/40 on a local simulator.