Struct goose::goose::Scenario

source ·
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§

source§

impl Scenario

source

pub fn new(name: &str) -> Self

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");
source

pub fn register_transaction(self, transaction: Transaction) -> Self

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(())
}
source

pub fn set_weight(self, weight: usize) -> Result<Self, GooseError>

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(())
}
source

pub fn set_host(self, host: &str) -> Self

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");
source

pub fn set_wait_time( self, min_wait: Duration, max_wait: Duration ) -> Result<Self, GooseError>

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§

source§

impl Clone for Scenario

source§

fn clone(&self) -> Scenario

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Hash for Scenario

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for Twhere T: Any,

source§

fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>

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.
source§

fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T, Global>) -> Arc<dyn Any + Send + Sync, Global>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> GooseUserData for Twhere T: Send + Sync + 'static,