Skip to content

Commit

Permalink
move async to launch_clients()
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyandrews committed May 16, 2020
1 parent 8986b3d commit afee6f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ reqwest = { version = "0.10", features = ["blocking", "cookies", "json"] }
serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.11"
simplelog = "0.7"
structopt = "0.3"
tokio = { version = "0.2.20", features = ["rt-core", "time"] }
url = "2.1"

Expand Down
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,7 @@ impl GooseAttack {
/// let _response = client.get("/bar");
/// }
/// ```
pub fn execute(self) {
let mut rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(self.execute_async())
}

async fn execute_async(mut self) {
pub fn execute(mut self) {
// At least one task set is required.
if self.task_sets.len() <= 0 {
error!("No task sets defined.");
Expand Down Expand Up @@ -835,7 +830,8 @@ impl GooseAttack {
}
// Start goose in single-process mode.
else {
self = self.launch_clients(started, sleep_duration, None);
let mut rt = tokio::runtime::Runtime::new().unwrap();
self = rt.block_on(self.launch_clients(started, sleep_duration, None));
}

if !self.configuration.no_stats && !self.configuration.worker {
Expand All @@ -844,7 +840,7 @@ impl GooseAttack {
}

/// Called internally in local-mode and gaggle-mode.
pub fn launch_clients(mut self, mut started: time::Instant, sleep_duration: time::Duration, socket: Option<Socket>) -> GooseAttack {
async fn launch_clients(mut self, mut started: time::Instant, sleep_duration: time::Duration, socket: Option<Socket>) -> GooseAttack {
trace!("launch clients: started({:?}) sleep_duration({:?}) socket({:?})", started, sleep_duration, socket);
// Collect client threads in a vector for when we want to stop them later.
let mut clients = vec![];
Expand Down
3 changes: 2 additions & 1 deletion src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ pub fn worker_main(state: &GooseAttack) {
}
goose_state.weighted_clients = weighted_clients;
goose_state.configuration.worker = true;
goose_state.launch_clients(started, sleep_duration, Some(manager));
let mut rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(goose_state.launch_clients(started, sleep_duration, Some(manager)));
}

pub fn push_stats_to_manager(manager: &Socket, requests: &HashMap<String, GooseRequest>, get_response: bool) -> bool {
Expand Down

0 comments on commit afee6f3

Please sign in to comment.