diff --git a/Cargo.toml b/Cargo.toml index 45466440..33f758d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ serde = { version = "1.0", features = ["derive"] } serde_cbor = "0.11" serde_json = "1.0" simplelog = "0.8" -tokio = { version = "0.3", features = ["fs", "io-util", "macros", "rt", "sync", "time"] } +tokio = { version = "0.3", features = ["fs", "io-util", "macros", "rt-multi-thread", "sync", "time"] } url = "2.1" # optional dependencies diff --git a/src/lib.rs b/src/lib.rs index 451c9b24..c7f791b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -433,6 +433,7 @@ use std::{f32, fmt, io, time}; use tokio::fs::File; use tokio::io::BufWriter; use tokio::prelude::*; +use tokio::runtime::Runtime; use tokio::sync::mpsc; use url::Url; @@ -2019,7 +2020,7 @@ impl GooseAttack { if self.attack_mode == GooseMode::Manager { #[cfg(feature = "gaggle")] { - let mut rt = tokio::runtime::Runtime::new().unwrap(); + let rt = Runtime::new().unwrap(); self = rt.block_on(manager::manager_main(self)); } @@ -2034,7 +2035,7 @@ impl GooseAttack { else if self.attack_mode == GooseMode::Worker { #[cfg(feature = "gaggle")] { - let mut rt = tokio::runtime::Runtime::new().unwrap(); + let rt = Runtime::new().unwrap(); self = rt.block_on(worker::worker_main(&self)); } @@ -2048,7 +2049,7 @@ impl GooseAttack { } // Start goose in single-process mode. else { - let mut rt = tokio::runtime::Runtime::new().unwrap(); + let rt = Runtime::new().unwrap(); self = rt.block_on(self.launch_users(sleep_duration, None))?; } @@ -2164,7 +2165,7 @@ impl GooseAttack { throttle_rx, ))); - let mut sender = all_threads_throttle.clone(); + let sender = all_threads_throttle.clone(); // We start from 1 instead of 0 to intentionally fill all but one slot in the // channel to avoid a burst of traffic during startup. The channel then provides // an implementation of the leaky bucket algorithm as a queue. Requests have to @@ -2501,7 +2502,7 @@ impl GooseAttack { } // If throttle is enabled, tell throttle thread the load test is over. - if let Some(mut tx) = parent_to_throttle_tx { + if let Some(tx) = parent_to_throttle_tx { let _ = tx.send(false).await; } @@ -2552,7 +2553,7 @@ impl GooseAttack { } let one_second = time::Duration::from_secs(1); - tokio::time::delay_for(one_second).await; + tokio::time::sleep(one_second).await; } self.metrics.duration = self.started.unwrap().elapsed().as_secs() as usize; diff --git a/src/user.rs b/src/user.rs index 44c43429..798a36b4 100644 --- a/src/user.rs +++ b/src/user.rs @@ -132,7 +132,7 @@ pub async fn user_main( "user {} from {} sleeping {:?} second...", thread_number, thread_task_set.name, sleep_duration ); - tokio::time::delay_for(sleep_duration).await; + tokio::time::sleep(sleep_duration).await; slept += 1; if slept > wait_time { in_sleep_loop = false; diff --git a/src/util.rs b/src/util.rs index 2d95f180..612fdf70 100644 --- a/src/util.rs +++ b/src/util.rs @@ -52,7 +52,7 @@ pub async fn sleep_minus_drift( drift: tokio::time::Instant, ) -> tokio::time::Instant { match duration.checked_sub(drift.elapsed()) { - Some(delay) if delay.as_nanos() > 0 => tokio::time::delay_for(delay).await, + Some(delay) if delay.as_nanos() > 0 => tokio::time::sleep(delay).await, _ => warn!("sleep_minus_drift: drift was greater than or equal to duration, not sleeping"), }; tokio::time::Instant::now() diff --git a/tests/sequence.rs b/tests/sequence.rs index 66ea46e9..46005ed6 100644 --- a/tests/sequence.rs +++ b/tests/sequence.rs @@ -1,7 +1,7 @@ use httpmock::Method::GET; use httpmock::{Mock, MockRef, MockServer}; use serial_test::serial; -use tokio::time::{delay_for, Duration}; +use tokio::time::{sleep, Duration}; mod common; @@ -50,7 +50,7 @@ pub async fn two_with_delay(user: &GooseUser) -> GooseTaskResult { // "Run out the clock" on the load test when this function runs. Sleep for // the total duration the test is to run plus 1 second to be sure no // additional tasks will run after this one. - delay_for(Duration::from_secs(RUN_TIME as u64 + 1)).await; + sleep(Duration::from_secs(RUN_TIME as u64 + 1)).await; Ok(()) }