Skip to content

Commit 06850f7

Browse files
TheSentinel454Elrondclaude
committed
test(relay): wait for every waiter to reach the gate before filling the cache
The shared-read test yielded once and then filled the cache, so a waiter spawned late could take the initial cache-hit path and pass without exercising the waiter branch. Each waiter holds a clone of the leader's gate while it waits; the test now waits for the gate's count to show all eight before it fills the cache. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Luke Tornquist <[email protected]>
1 parent a6c09c9 commit 06850f7

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎crates/buzz-relay/src/state.rs‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,6 +4331,21 @@ pub(crate) mod tests {
43314331
own_banned: false,
43324332
muted_until: Some(chrono::Utc::now() + chrono::Duration::hours(1)),
43334333
};
4334+
// Every waiter holds a clone of the leader's gate while it waits, so
4335+
// the gate's count proves all of them reached it before the cache
4336+
// is filled; none can take the initial cache-hit path instead.
4337+
async fn enrolled(gate: Option<Arc<tokio::sync::Mutex<()>>>, waiters: usize) {
4338+
let gate = gate.expect("the leader's gate");
4339+
let base = Arc::strong_count(&gate);
4340+
let start = Instant::now();
4341+
while Arc::strong_count(&gate) < base + waiters {
4342+
assert!(
4343+
start.elapsed() < std::time::Duration::from_millis(500),
4344+
"waiters did not reach the gate"
4345+
);
4346+
tokio::time::sleep(std::time::Duration::from_millis(5)).await;
4347+
}
4348+
}
43344349

43354350
let leader = state
43364351
.restriction_reads
@@ -4346,7 +4361,11 @@ pub(crate) mod tests {
43464361
)
43474362
})
43484363
.collect::<Vec<_>>();
4349-
tokio::task::yield_now().await;
4364+
enrolled(
4365+
state.restriction_reads.gate(&(community, pubkey.clone())),
4366+
waiters.len(),
4367+
)
4368+
.await;
43504369
state.seed_restriction((community, pubkey.clone()), muted.clone());
43514370
drop(leader);
43524371
for waiter in waiters {
@@ -4366,7 +4385,7 @@ pub(crate) mod tests {
43664385
tokio::spawn(async move { state.resolve_host(&host).await })
43674386
})
43684387
.collect::<Vec<_>>();
4369-
tokio::task::yield_now().await;
4388+
enrolled(state.tenant_host_reads.gate(&host), waiters.len()).await;
43704389
state
43714390
.tenant_host_cache
43724391
.insert(host.clone(), (community, Instant::now()));

0 commit comments

Comments
 (0)