Skip to content

Commit 66f1246

Browse files
committed
test(tracker-core): wait for downloads==1 instead of asserting on intermediate state
In `it_should_persist_the_number_of_completed_peers_for_each_torrent_into_the_database`, the retry loop previously asserted `swarm_metadata.downloads() == 1` on the first observation. If the background event listener has stored the row but not yet updated the in-memory `downloads` counter, that assertion would panic the test instead of letting the bounded `tokio::time::timeout` wait for the desired state. Change the check to `if downloads() == 1 { break true }` so the timeout actually governs the wait and intermediate observations are tolerated. Addresses Copilot review comment #17 on PR #1718.
1 parent fd5be6d commit 66f1246

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

packages/tracker-core/tests/integration.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ async fn it_should_persist_the_number_of_completed_peers_for_each_torrent_into_t
8080
// Load torrents from the database to ensure the completed stats are persisted.
8181
// Bound the wait with a timeout instead of a fixed iteration count so the
8282
// test fails loudly on a stalled system rather than after an arbitrary
83-
// number of immediate retries.
83+
// number of immediate retries. Re-check the desired state (`downloads == 1`)
84+
// inside the retry condition so an intermediate observation does not
85+
// panic the test before the background listener has finished applying
86+
// the persisted value.
8487
let restored = tokio::time::timeout(std::time::Duration::from_secs(5), async {
8588
loop {
8689
test_env
@@ -91,8 +94,9 @@ async fn it_should_persist_the_number_of_completed_peers_for_each_torrent_into_t
9194
.unwrap();
9295

9396
if let Some(swarm_metadata) = test_env.get_swarm_metadata(&info_hash).await {
94-
assert!(swarm_metadata.downloads() == 1);
95-
break true;
97+
if swarm_metadata.downloads() == 1 {
98+
break true;
99+
}
96100
}
97101

98102
tokio::time::sleep(std::time::Duration::from_millis(50)).await;

0 commit comments

Comments
 (0)