Struct goose::goose::GooseTask [−][src]
pub struct GooseTask { pub tasks_index: usize, pub name: String, pub weight: usize, pub sequence: usize, pub on_start: bool, pub on_stop: bool, pub function: GooseTaskFunction, }
Expand description
An individual task within a GooseTaskSet
.
Fields
tasks_index: usize
Expand description
An index into GooseTaskSet
.task
, indicating which
task this is.
name: String
Expand description
An optional name for the task, used when displaying metrics about requests made.
weight: usize
Expand description
An integer value that controls the frequency that this task will be run.
sequence: usize
Expand description
An integer value that controls when this task runs compared to other tasks in the same
GooseTaskSet
.
on_start: bool
Expand description
A flag indicating that this task runs when the user starts.
on_stop: bool
Expand description
A flag indicating that this task runs when the user stops.
function: GooseTaskFunction
Expand description
A required function that is executed each time this task runs.
Implementations
impl GooseTask
[src]
impl GooseTask
[src]pub fn new(function: GooseTaskFunction) -> Self
[src]
pub fn set_name(self, name: &str) -> Self
[src]
pub fn set_name(self, name: &str) -> Self
[src]Set an optional name for the task, used when displaying metrics about requests made by the task.
Individual requests can also be named withing your load test if you use the
_named
version of each method, for example
get_named
or
post_named
.
Example
use goose::prelude::*; task!(my_task_function).set_name("foo"); async fn my_task_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/").await?; Ok(()) }
pub fn set_on_start(self) -> Self
[src]
pub fn set_on_start(self) -> Self
[src]Set an optional flag indicating that this task should be run when a user first starts. This could be used to log the user in, and so all subsequent tasks are done as a logged in user. A task with this flag set will only run at start time (and optionally at stop time as well, if that flag is also set).
On-start tasks can be sequenced and weighted. Sequences allow multiple on-start tasks to run in a controlled order. Weights allow on-start tasks to run multiple times when a user starts.
Example
use goose::prelude::*; task!(my_on_start_function).set_on_start(); async fn my_on_start_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/").await?; Ok(()) }
pub fn set_on_stop(self) -> Self
[src]
pub fn set_on_stop(self) -> Self
[src]Set an optional flag indicating that this task should be run when a user stops. This could be used to log a user out when the user finishes its load test. A task with this flag set will only run at stop time (and optionally at start time as well, if that flag is also set).
On-stop tasks can be sequenced and weighted. Sequences allow multiple on-stop tasks to run in a controlled order. Weights allow on-stop tasks to run multiple times when a user stops.
Example
use goose::prelude::*; task!(my_on_stop_function).set_on_stop(); async fn my_on_stop_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/").await?; Ok(()) }
pub fn set_weight(self, weight: usize) -> Result<Self, GooseError>
[src]
pub fn set_weight(self, weight: usize) -> Result<Self, GooseError>
[src]Sets a weight on an individual task. The larger the value of weight, the more often it will be run in the TaskSet. For example, if one task has a weight of 3 and another task has a weight of 1, the first task will run 3 times as often.
Example
use goose::prelude::*; fn main() -> Result<(), GooseError> { task!(task_function).set_weight(3)?; Ok(()) } async fn task_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/").await?; Ok(()) }
pub fn set_sequence(self, sequence: usize) -> Self
[src]
pub fn set_sequence(self, sequence: usize) -> Self
[src]Defines the sequence value of an individual tasks. Tasks are run in order of their sequence value, so a task with a sequence value of 1 will run before a task with a sequence value of 2. Tasks with no sequence value (or a sequence value of 0) will run last, after all tasks with positive sequence values.
All tasks with the same sequence value will run in a random order. Tasks can be assigned both squence values and weights.
Examples
In this first example, the variable names indicate the order the tasks will be run in:
use goose::prelude::*; let runs_first = task!(first_task_function).set_sequence(3); let runs_second = task!(second_task_function).set_sequence(5835); let runs_last = task!(third_task_function); async fn first_task_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/1").await?; Ok(()) } async fn second_task_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/2").await?; Ok(()) } async fn third_task_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/3").await?; Ok(()) }
In the following example, the runs_first
task runs two times, then one instance of runs_second
and two instances of also_runs_second
are all three run. The user will do this over and over
the entire time it runs, with runs_first
always running first, then the other tasks being
run in a random and weighted order:
use goose::prelude::*; fn main() -> Result<(), GooseError> { let runs_first = task!(first_task_function).set_sequence(1).set_weight(2)?; let runs_second = task!(second_task_function_a).set_sequence(2); let also_runs_second = task!(second_task_function_b).set_sequence(2).set_weight(2)?; Ok(()) } async fn first_task_function(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/1").await?; Ok(()) } async fn second_task_function_a(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/2a").await?; Ok(()) } async fn second_task_function_b(user: &GooseUser) -> GooseTaskResult { let _goose = user.get("/2b").await?; Ok(()) }
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for GooseTask
impl Send for GooseTask
impl Sync for GooseTask
impl Unpin for GooseTask
impl !UnwindSafe for GooseTask
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,