From 654102a17dfd04951771927c826bfc7ee000e0a8 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 18 Sep 2026 14:23:08 +0000 Subject: [PATCH] test(common): connect verify_event_not_served through connect_client verify_event_not_served connected with `Client::connect` and then slept 100 ms per status poll for up to two seconds before the first query. The sleep-first loop paid at least one interval on every call and, under scheduler pressure, could miss the connected transition and report a false connection failure. Use the shared `connect_client` helper, which awaits the connection attempt itself and fails the test with the SDK's reason. The absence check that follows is unchanged. Validation: `cargo check -p ngit-grasp --tests`; the callers are covered by the purgatory and lifecycle binaries measured in the following commits. Assisted-by: Claude Fable 5.1 Co-Authored-By: Claude Fable 5.1 --- tests/common/purgatory_helpers.rs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/tests/common/purgatory_helpers.rs b/tests/common/purgatory_helpers.rs index 8e37e17..69937fd 100644 --- a/tests/common/purgatory_helpers.rs +++ b/tests/common/purgatory_helpers.rs @@ -16,6 +16,8 @@ use nostr_sdk::prelude::*; use std::path::Path; use std::time::Duration; +use super::relay::connect_client; + // NOTE: Using rust-nostr Kind variants: // - Kind::RepoState.as_u16() -> Kind::RepoState (30618) // - Kind::GitPullRequest.as_u16() -> Kind::GitPullRequest (1618) @@ -452,24 +454,7 @@ pub async fn verify_event_not_served( .add_relay(relay_url) .await .map_err(|e| format!("Failed to add relay: {}", e))?; - - client.connect().await; - - // Wait for connection - let mut connected = false; - for _ in 0..20 { - tokio::time::sleep(Duration::from_millis(100)).await; - let relays = client.relays().await; - if relays.values().any(|r| r.status().is_connected()) { - connected = true; - break; - } - } - - if !connected { - client.disconnect().await; - return Err("Failed to connect to relay".to_string()); - } + connect_client(&client).await; // Check that event is NOT served let filter = Filter::new().id(*event_id);