Skip to content

Commit df7c2d1

Browse files
committed
test: cleanup test setup further
1 parent 2dec813 commit df7c2d1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/robust_provider/subscription.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ mod tests {
380380
trigger_failover_with_delay(stream, next_provider, expected_block, Duration::ZERO).await
381381
}
382382

383+
/// Waits for timeout and asserts a backend gone or timeout error.
384+
async fn assert_timeout_error(
385+
stream: &mut RobustSubscriptionStream<alloy::network::Ethereum>,
386+
extra_delay: Duration,
387+
) {
388+
sleep(SHORT_TIMEOUT + extra_delay + BUFFER_TIME).await;
389+
let err = stream.next().await.unwrap().unwrap_err();
390+
assert_backend_gone_or_timeout(err);
391+
}
392+
383393
#[tokio::test]
384394
async fn ws_fails_http_fallback_returns_primary_error() -> anyhow::Result<()> {
385395
// Setup: Create WS primary and HTTP fallback
@@ -407,13 +417,7 @@ mod tests {
407417
assert_next_block!(stream, 2);
408418

409419
// Verify: HTTP fallback can't provide subscription, so we get an error
410-
let task = tokio::spawn(async move {
411-
sleep(SHORT_TIMEOUT + BUFFER_TIME).await;
412-
http_provider.anvil_mine(Some(1), None).await.unwrap();
413-
});
414-
let err = stream.next().await.unwrap().unwrap_err();
415-
task.await?;
416-
assert_backend_gone_or_timeout(err);
420+
assert_timeout_error(&mut stream, Duration::ZERO).await;
417421

418422
let next = stream.next().await;
419423
assert!(next.is_none(), "Expected stream to be finished, got: {next:?}");
@@ -522,9 +526,7 @@ mod tests {
522526
assert_next_block!(stream, 2);
523527

524528
// FP2 times out -> tries PP (fails) -> no more fallbacks -> error
525-
sleep(SHORT_TIMEOUT * 2 + BUFFER_TIME).await;
526-
let err = stream.next().await.unwrap().unwrap_err();
527-
assert_backend_gone_or_timeout(err);
529+
assert_timeout_error(&mut stream, SHORT_TIMEOUT).await;
528530

529531
Ok(())
530532
}
@@ -545,9 +547,7 @@ mod tests {
545547
assert_next_block!(stream, 1);
546548

547549
// No fallback available - should error after timeout
548-
sleep(SHORT_TIMEOUT + BUFFER_TIME).await;
549-
let err = stream.next().await.unwrap().unwrap_err();
550-
assert_backend_gone_or_timeout(err);
550+
assert_timeout_error(&mut stream, Duration::ZERO).await;
551551

552552
Ok(())
553553
}

0 commit comments

Comments
 (0)