Skip to content

Commit

Permalink
dev: add timeouts to udp test-env setup and shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed May 18, 2024
1 parent 9c607a7 commit 438dae2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/shared/bit_torrent/tracker/udp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
11 changes: 9 additions & 2 deletions tests/servers/udp/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,16 +57,22 @@ impl Environment<Stopped> {

impl Environment<Running> {
pub async fn new(configuration: &Arc<Configuration>) -> Self {
Environment::<Stopped>::new(configuration).start().await
tokio::time::timeout(DEFAULT_TIMEOUT, Environment::<Stopped>::new(configuration).start())
.await
.expect("it should create an environment within the timeout")
}

#[allow(dead_code)]
pub async fn stop(self) -> Environment<Stopped> {
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"),
}
}

Expand Down

0 comments on commit 438dae2

Please sign in to comment.