Skip to content

test(torrent): check web seed stalls at fixed times, after the peers they count - #594

Merged
linroid merged 1 commit into
mainfrom
test/web-seed-stall-checks
Oct 18, 2026
Merged

linroid merged 1 commit into
mainfrom
test/web-seed-stall-checks

Conversation

@linroid

@linroid linroid commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Problem

TorrentWebSeedTest.peerReconnectingAfterARelaunch_clearsWhatWasMissingOnlyWithThosePieces failed 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 holding stale.bin connects.

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's awaitStall stepped 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 with stale.bin still unheld. I confirmed this by delaying the bitfield handoff in TorrentSwarm by 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 / 1000 picks out that check. Before each check, the tests wait for what it should see:

  • the swarm's bitfield on the peer's wire, which it sends right after it counts the peer;
  • its INTERESTED to the peer holding stale.bin, sent once that peer's bitfield is in the scheduler (as peerLackingAPiece_… already does);
  • for the peer that leaves, the buffer budget dropping, since the swarm frees a peer's lease right after it removes the peer from the connected set.

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 --rerun while every core ran a busy loop (40/40 each), and once more on the final tree.
  • With the bitfield handoff delayed by 1 s: both new tests pass, and the old peerReconnecting… fails at line 890 with expected:<CHOKED> but was:<MISSING_PIECES>.
  • ./gradlew :library:torrent:compileTestKotlinIosSimulatorArm64 passes.
  • ./gradlew :library:torrent:iosSimulatorArm64Test -PenableIosSimulatorTests=true --tests '*TorrentWebSeedTest*': 40/40 on a local simulator.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-18T01:49:08.697667Z ba86d93 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 18, 2026

Copy link
Copy Markdown

Code review

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

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 116 files  ±0   2 144 suites  ±0   42m 34s ⏱️ +24s
14 600 tests ±0  14 332 ✅ +1  268 💤 ±0  0 ❌  - 1 
17 749 runs  ±0  17 481 ✅ +1  268 💤 ±0  0 ❌  - 1 

Results for commit ba86d93. ± Comparison against base commit ad6751e.

@linroid
linroid merged commit 9963149 into main Oct 18, 2026
15 checks passed
@linroid
linroid deleted the test/web-seed-stall-checks branch October 18, 2026 02:20
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