From 3b58f5a1112d5927e3f050caa50c4381b53fcc68 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 18 Mar 2025 05:50:28 +0100 Subject: [PATCH] Add delay for test server availability, could cause connect race (#533) --- ntex-server/src/net/test.rs | 12 +++++++----- ntex/CHANGES.md | 4 ++++ ntex/src/http/test.rs | 8 ++++++-- ntex/src/web/test.rs | 5 ++++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ntex-server/src/net/test.rs b/ntex-server/src/net/test.rs index 2ddae445..1c78f5c5 100644 --- a/ntex-server/src/net/test.rs +++ b/ntex-server/src/net/test.rs @@ -59,17 +59,19 @@ where .workers(1) .disable_signals() .run(); - tx.send((system, local_addr, server)) - .expect("Failed to send Server to TestServer"); + + ntex_rt::spawn(async move { + ntex_util::time::sleep(ntex_util::time::Millis(75)).await; + tx.send((system, local_addr, server)) + .expect("Failed to send Server to TestServer"); + }); + Ok(()) }) }); let (system, addr, server) = rx.recv().unwrap(); - // wait for server - thread::sleep(std::time::Duration::from_millis(50)); - TestServer { addr, server, diff --git a/ntex/CHANGES.md b/ntex/CHANGES.md index 4a665b57..2e6b077e 100644 --- a/ntex/CHANGES.md +++ b/ntex/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [2.12.3] - 2025-03-xx + +* http: Add delay for test server availability, could cause connect race + ## [2.12.2] - 2025-03-15 * http: Allow to run publish future to completion in case error diff --git a/ntex/src/http/test.rs b/ntex/src/http/test.rs index cff51af4..60dfbf17 100644 --- a/ntex/src/http/test.rs +++ b/ntex/src/http/test.rs @@ -11,7 +11,7 @@ use crate::server::Server; use crate::service::ServiceFactory; #[cfg(feature = "ws")] use crate::ws::{error::WsClientError, WsClient, WsConnection}; -use crate::{rt::System, time::Millis, time::Seconds, util::Bytes}; +use crate::{rt::System, time::sleep, time::Millis, time::Seconds, util::Bytes}; use super::client::{Client, ClientRequest, ClientResponse, Connector}; use super::error::{HttpError, PayloadError}; @@ -244,7 +244,11 @@ where .workers(1) .disable_signals() .run(); - tx.send((system, srv, local_addr)).unwrap(); + + crate::rt::spawn(async move { + sleep(Millis(75)).await; + tx.send((system, srv, local_addr)).unwrap(); + }); Ok(()) }) }); diff --git a/ntex/src/web/test.rs b/ntex/src/web/test.rs index 6a0bcabc..e977c3b9 100644 --- a/ntex/src/web/test.rs +++ b/ntex/src/web/test.rs @@ -697,7 +697,10 @@ where .set_tag("test", "WEB-SRV") .run(); - tx.send((System::current(), srv, local_addr)).unwrap(); + crate::rt::spawn(async move { + sleep(Millis(75)).await; + tx.send((System::current(), srv, local_addr)).unwrap(); + }); Ok(()) }) });