pub struct Scenario {
    pub name: String,
    pub machine_name: String,
    pub scenarios_index: usize,
    pub weight: usize,
    pub transaction_wait: Option<(Duration, Duration)>,
    pub transactions: Vec<Transaction>,
    pub weighted_transactions: Vec<(usize, String)>,
    pub weighted_on_start_transactions: Vec<(usize, String)>,
    pub weighted_on_stop_transactions: Vec<(usize, String)>,
    pub host: Option<String>,
}
Expand description

An individual scenario.

Fields

name: String

The name of the scenario.

machine_name: String

Auto-generated machine name of the scenario.

scenarios_index: usize

An integer reflecting where this scenario lives in the internal GooseAttack.scenarios vector.

weight: usize

An integer value that controls the frequency that this scenario will be assigned to a user.

transaction_wait: Option<(Duration, Duration)>

A Duration range defining the minimum and maximum time a GooseUser should sleep after running a transaction.

transactions: Vec<Transaction>

A vector containing one copy of each Transaction that will run by users running this scenario.

weighted_transactions: Vec<(usize, String)>

A fully scheduled and weighted vector of integers (pointing to Transactions and Transaction names.

weighted_on_start_transactions: Vec<(usize, String)>

A vector of vectors of integers, controlling the sequence and order on_start Transactions are run when the user first starts.

weighted_on_stop_transactions: Vec<(usize, String)>

A vector of vectors of integers, controlling the sequence and order on_stop Transactions are run when the user first starts.

host: Option<String>

An optional default host to run this Scenario against.

Implementations

Creates a new Scenario. Once created, a Transaction must be assigned to it, and finally it must be registered with the GooseAttack object. The returned object must be stored in a mutable value.

Example
use goose::prelude::*;

let mut example_transactions = scenario!("ExampleTransactions");

Registers a Transaction with a Scenario, where it is stored in the Scenario.transactions vector. The function associated with the transaction will be run during the load test.

Example
use goose::prelude::*;

let mut example_transactions = scenario!("ExampleTransactions");
example_transactions.register_transaction(transaction!(a_transaction_function));

/// A very simple transaction that loads the "a" page.
async fn a_transaction_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("a/").await?;

    Ok(())
}

Sets a weight on a scenario. The larger the value of weight, the more often the scenario will be assigned to users. For example, if you have scenario foo with a weight of 3, and scenario bar with a weight of 1, and you spin up a load test with 8 users, 6 of them will be running the foo scenario, and 2 will be running the bar scenario.

Example
use goose::prelude::*;

#[tokio::main]
async fn main() -> Result<(), GooseError> {
    let mut example_transactions = scenario!("ExampleTransactions").set_weight(3)?;

    Ok(())
}

Set a default host for the scenario. If no --host flag is set when running the load test, this host will be pre-pended on all requests. For example, this can configure your load test to run against your local development environment by default, and the --host option could be used to override host when running the load test against production.

Example
use goose::prelude::*;

let mut example_transactions = scenario!("ExampleTransactions").set_host("http://10.1.1.42");

Configure a senario to to pause after running each transaction. The length of the pause will be randomly selected from min_wait to max_wait inclusively.

Example
use goose::prelude::*;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), GooseError> {
    scenario!("ExampleTransactions").set_wait_time(Duration::from_secs(0), Duration::from_secs(1))?;

    Ok(())
}

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more