F: dedupe the repeated peers test block
This commit is contained in:
1 parent
2af03308ba
commit
f894d7da17
1 file changed
+20
-27
+20
-27
@@ -416,6 +416,24 @@ async fn assert_oversize_refused(source: &Listener, token: &Path) {
|
||||
consolidator.stop().await;
|
||||
}
|
||||
|
||||
/// Asserts that the 1 s request deadline ends the call as a timeout. The bound
|
||||
/// is 4 s rather than 10 s so a deadline that never fired cannot pass.
|
||||
async fn assert_peer_times_out(source: &Listener, token: &Path) {
|
||||
let mut cfg = one_peer("beta", source.url("http"), None, token);
|
||||
cfg.request_timeout_secs = 1;
|
||||
let consolidator = Consolidator::start(cfg).await;
|
||||
|
||||
let started = std::time::Instant::now();
|
||||
let (code, _, body) = consolidator
|
||||
.get("/api/v1/peers/beta/systemd/units", None)
|
||||
.await;
|
||||
let elapsed = started.elapsed();
|
||||
assert_eq!(code, 503, "{body}");
|
||||
assert!(body.contains("timeout"), "{body}");
|
||||
assert!(elapsed < Duration::from_secs(4), "took {elapsed:?}");
|
||||
consolidator.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_plain_peer_reports_up_and_auth_ok() {
|
||||
let dir = TempDir::new("plain");
|
||||
@@ -628,20 +646,7 @@ async fn a_silent_peer_times_out_within_the_request_timeout() {
|
||||
let dir = TempDir::new("slow");
|
||||
let source = Listener::start(|| None).await;
|
||||
let token = dir.write("peer-token", "slow-token\n".as_bytes(), 0o600);
|
||||
let mut cfg = one_peer("beta", source.url("http"), None, &token);
|
||||
cfg.request_timeout_secs = 1;
|
||||
let consolidator = Consolidator::start(cfg).await;
|
||||
|
||||
let started = std::time::Instant::now();
|
||||
let (code, _, body) = consolidator
|
||||
.get("/api/v1/peers/beta/systemd/units", None)
|
||||
.await;
|
||||
let elapsed = started.elapsed();
|
||||
assert_eq!(code, 503, "{body}");
|
||||
assert!(body.contains("timeout"), "{body}");
|
||||
// With a 1 s timeout, a 10 s bound would hide a deadline that never fired.
|
||||
assert!(elapsed < Duration::from_secs(4), "took {elapsed:?}");
|
||||
consolidator.stop().await;
|
||||
assert_peer_times_out(&source, &token).await;
|
||||
}
|
||||
|
||||
/// No Content-Length to precheck: only the counting of chunk bytes can refuse
|
||||
@@ -681,20 +686,8 @@ async fn a_trickling_peer_times_out_within_the_request_timeout() {
|
||||
})
|
||||
.await;
|
||||
let token = dir.write("peer-token", "trickle-token\n".as_bytes(), 0o600);
|
||||
let mut cfg = one_peer("beta", source.url("http"), None, &token);
|
||||
cfg.request_timeout_secs = 1;
|
||||
let consolidator = Consolidator::start(cfg).await;
|
||||
|
||||
let started = std::time::Instant::now();
|
||||
let (code, _, body) = consolidator
|
||||
.get("/api/v1/peers/beta/systemd/units", None)
|
||||
.await;
|
||||
let elapsed = started.elapsed();
|
||||
assert_eq!(code, 503, "{body}");
|
||||
assert!(body.contains("timeout"), "{body}");
|
||||
assert!(elapsed < Duration::from_secs(4), "took {elapsed:?}");
|
||||
assert_peer_times_out(&source, &token).await;
|
||||
assert!(source.hits() > 0);
|
||||
consolidator.stop().await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user