diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 00:50:54 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 00:50:54 +0000 |
| commit | f75e1c59aacf5ce668fd327e4e3d827511661c2a (patch) | |
| tree | 867926c7503e7c587e86c67896a9e7347600447b /tests/common/mock_relay.rs | |
| parent | 3f14f998d64b5fa15bdddd7570b4f72874eb9f29 (diff) | |
chore: cargo fmt
Diffstat (limited to 'tests/common/mock_relay.rs')
| -rw-r--r-- | tests/common/mock_relay.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/tests/common/mock_relay.rs b/tests/common/mock_relay.rs index b6376a7..e81c453 100644 --- a/tests/common/mock_relay.rs +++ b/tests/common/mock_relay.rs | |||
| @@ -73,8 +73,8 @@ impl MockRelay { | |||
| 73 | /// in an in-memory database. | 73 | /// in an in-memory database. |
| 74 | pub async fn start() -> Self { | 74 | pub async fn start() -> Self { |
| 75 | // Create and bind listener (eliminates port race condition) | 75 | // Create and bind listener (eliminates port race condition) |
| 76 | let std_listener = std::net::TcpListener::bind("127.0.0.1:0") | 76 | let std_listener = |
| 77 | .expect("Failed to bind to random port"); | 77 | std::net::TcpListener::bind("127.0.0.1:0").expect("Failed to bind to random port"); |
| 78 | let port = std_listener | 78 | let port = std_listener |
| 79 | .local_addr() | 79 | .local_addr() |
| 80 | .expect("Failed to get local addr") | 80 | .expect("Failed to get local addr") |
| @@ -84,8 +84,8 @@ impl MockRelay { | |||
| 84 | std_listener | 84 | std_listener |
| 85 | .set_nonblocking(true) | 85 | .set_nonblocking(true) |
| 86 | .expect("Failed to set non-blocking"); | 86 | .expect("Failed to set non-blocking"); |
| 87 | let listener = TcpListener::from_std(std_listener) | 87 | let listener = |
| 88 | .expect("Failed to convert to tokio listener"); | 88 | TcpListener::from_std(std_listener).expect("Failed to convert to tokio listener"); |
| 89 | 89 | ||
| 90 | Self::start_with_listener(listener, port).await | 90 | Self::start_with_listener(listener, port).await |
| 91 | } | 91 | } |
| @@ -258,7 +258,10 @@ fn derive_accept_key(request_key: &[u8]) -> String { | |||
| 258 | engine.input(request_key); | 258 | engine.input(request_key); |
| 259 | engine.input(WS_GUID); | 259 | engine.input(WS_GUID); |
| 260 | let hash = Sha1Hash::from_engine(engine); | 260 | let hash = Sha1Hash::from_engine(engine); |
| 261 | base64::Engine::encode(&base64::engine::general_purpose::STANDARD, hash.as_byte_array()) | 261 | base64::Engine::encode( |
| 262 | &base64::engine::general_purpose::STANDARD, | ||
| 263 | hash.as_byte_array(), | ||
| 264 | ) | ||
| 262 | } | 265 | } |
| 263 | 266 | ||
| 264 | /// Wait for the server to be ready to accept connections. | 267 | /// Wait for the server to be ready to accept connections. |
| @@ -275,10 +278,7 @@ async fn wait_for_server_ready(port: u16) { | |||
| 275 | } | 278 | } |
| 276 | Err(_) => { | 279 | Err(_) => { |
| 277 | if attempt == max_attempts - 1 { | 280 | if attempt == max_attempts - 1 { |
| 278 | panic!( | 281 | panic!("MockRelay failed to start after {} attempts", max_attempts); |
| 279 | "MockRelay failed to start after {} attempts", | ||
| 280 | max_attempts | ||
| 281 | ); | ||
| 282 | } | 282 | } |
| 283 | tokio::time::sleep(delay).await; | 283 | tokio::time::sleep(delay).await; |
| 284 | } | 284 | } |
| @@ -309,7 +309,10 @@ mod tests { | |||
| 309 | // Create a client and connect | 309 | // Create a client and connect |
| 310 | let keys = Keys::generate(); | 310 | let keys = Keys::generate(); |
| 311 | let client = Client::new(keys.clone()); | 311 | let client = Client::new(keys.clone()); |
| 312 | client.add_relay(mock.url()).await.expect("Failed to add relay"); | 312 | client |
| 313 | .add_relay(mock.url()) | ||
| 314 | .await | ||
| 315 | .expect("Failed to add relay"); | ||
| 313 | client.connect().await; | 316 | client.connect().await; |
| 314 | 317 | ||
| 315 | // Wait for connection | 318 | // Wait for connection |