diff --git a/src/shared/bit_torrent/tracker/udp/client.rs b/src/shared/bit_torrent/tracker/udp/client.rs index 35bac606..0df65c1c 100644 --- a/src/shared/bit_torrent/tracker/udp/client.rs +++ b/src/shared/bit_torrent/tracker/udp/client.rs @@ -15,7 +15,7 @@ use crate::shared::bit_torrent::tracker::udp::{source_address, MAX_PACKET_SIZE}; /// Default timeout for sending and receiving packets. And waiting for sockets /// to be readable and writable. -const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5); +pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5); #[allow(clippy::module_name_repetitions)] #[derive(Debug)] diff --git a/tests/servers/udp/environment.rs b/tests/servers/udp/environment.rs index c1fecbdd..bfe21453 100644 --- a/tests/servers/udp/environment.rs +++ b/tests/servers/udp/environment.rs @@ -5,6 +5,7 @@ use torrust_tracker::bootstrap::app::initialize_with_configuration; use torrust_tracker::core::Tracker; use torrust_tracker::servers::registar::Registar; use torrust_tracker::servers::udp::server::{Launcher, Running, Stopped, UdpServer}; +use torrust_tracker::shared::bit_torrent::tracker::udp::client::DEFAULT_TIMEOUT; use torrust_tracker_configuration::{Configuration, UdpTracker}; use torrust_tracker_primitives::info_hash::InfoHash; use torrust_tracker_primitives::peer; @@ -56,16 +57,22 @@ impl Environment { impl Environment { pub async fn new(configuration: &Arc) -> Self { - Environment::::new(configuration).start().await + tokio::time::timeout(DEFAULT_TIMEOUT, Environment::::new(configuration).start()) + .await + .expect("it should create an environment within the timeout") } #[allow(dead_code)] pub async fn stop(self) -> Environment { + let stopped = tokio::time::timeout(DEFAULT_TIMEOUT, self.server.stop()) + .await + .expect("it should stop the environment within the timeout"); + Environment { config: self.config, tracker: self.tracker, registar: Registar::default(), - server: self.server.stop().await.expect("it stop the udp tracker service"), + server: stopped.expect("it stop the udp tracker service"), } }