Skip to content

Commit

Permalink
consistency and documentation cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Andrews committed Oct 13, 2021
1 parent 81d4668 commit a4ba013
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
15 changes: 7 additions & 8 deletions src/goose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
//!
//! ### Task Set Wait Time
//!
//! Wait time is specified as a low-high integer range. Each time a task completes in
//! the task set, the user will pause for a random number of seconds inclusively between
//! Wait time is specified as a low-high Duration range. Each time a task completes in the
//! task set, the user will pause for a random number of milliseconds inclusively between
//! the low and high wait times. In the following example, users loading `foo` tasks will
//! sleep 0 to 3 seconds after each task completes, and users loading `bar` tasks will
//! sleep 0 to 2.5 seconds after each task completes, and users loading `bar` tasks will
//! sleep 5 to 10 seconds after each task completes.
//!
//! ```rust
//! use goose::prelude::*;
//! use std::time::Duration;
//!
//! let mut foo_tasks = taskset!("FooTasks").set_wait_time(Duration::from_secs(0), Duration::from_secs(3)).unwrap();
//! let mut foo_tasks = taskset!("FooTasks").set_wait_time(Duration::from_secs(0), Duration::from_millis(2500)).unwrap();
//! let mut bar_tasks = taskset!("BarTasks").set_wait_time(Duration::from_secs(5), Duration::from_secs(10)).unwrap();
//! ```
//! ## Creating Tasks
Expand Down Expand Up @@ -593,8 +593,7 @@ impl GooseTaskSet {
}

/// Configure a task_set to to pause after running each task. The length of the pause will be randomly
/// selected from `min_weight` to `max_wait` inclusively. For example, if `min_wait` is `0` and
/// `max_weight` is `2`, the user will randomly sleep for 0, 1 or 2 seconds after each task completes.
/// selected from `min_wait` to `max_wait` inclusively.
///
/// # Example
/// ```rust
Expand All @@ -610,8 +609,8 @@ impl GooseTaskSet {
/// ```
pub fn set_wait_time(
mut self,
min_wait: std::time::Duration,
max_wait: std::time::Duration,
min_wait: Duration,
max_wait: Duration,
) -> Result<Self, GooseError> {
trace!(
"{} set_wait time: min: {:?} max: {:?}",
Expand Down
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ use std::sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
Arc,
};
use std::{fmt, io, time};
use std::time::{self, Duration};
use std::{fmt, io};
use tokio::fs::File;

use crate::config::{GooseConfiguration, GooseDefaults};
Expand Down Expand Up @@ -550,9 +551,9 @@ pub enum GooseError {
/// Invalid wait time specified.
InvalidWaitTime {
// The specified minimum wait time.
min_wait: std::time::Duration,
min_wait: Duration,
// The specified maximum wait time.
max_wait: std::time::Duration,
max_wait: Duration,
/// An optional explanation of the error.
detail: String,
},
Expand Down Expand Up @@ -1804,9 +1805,9 @@ impl GooseAttack {
{
let sleep_delay = self.configuration.running_metrics.unwrap() * 1_000;
goose_attack_run_state.spawn_user_in_ms -= sleep_delay;
std::time::Duration::from_millis(sleep_delay as u64)
Duration::from_millis(sleep_delay as u64)
} else {
std::time::Duration::from_millis(goose_attack_run_state.spawn_user_in_ms as u64)
Duration::from_millis(goose_attack_run_state.spawn_user_in_ms as u64)
};
debug!("sleeping {:?}...", sleep_duration);
goose_attack_run_state.drift_timer =
Expand All @@ -1816,7 +1817,7 @@ impl GooseAttack {
// If enough users have been spawned, move onto the next attack phase.
if self.weighted_users.is_empty() {
// Pause a tenth of a second waiting for the final user to fully start up.
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
tokio::time::sleep(Duration::from_millis(100)).await;

if self.attack_mode == AttackMode::Worker {
info!(
Expand Down Expand Up @@ -2049,7 +2050,7 @@ impl GooseAttack {
if self.configuration.no_autostart {
// Sleep then check for further instructions.
if goose_attack_run_state.idle_status_displayed {
let sleep_duration = std::time::Duration::from_millis(250);
let sleep_duration = Duration::from_millis(250);
debug!("sleeping {:?}...", sleep_duration);
goose_attack_run_state.drift_timer = util::sleep_minus_drift(
sleep_duration,
Expand Down
3 changes: 1 addition & 2 deletions src/user.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rand::Rng;
use std::time;
use std::time::Duration;
use std::time::{self, Duration};

use crate::get_worker_id;
use crate::goose::{GooseTaskFunction, GooseTaskSet, GooseUser, GooseUserCommand};
Expand Down

0 comments on commit a4ba013

Please sign in to comment.