Struct goose::goose::Transaction

source ·
pub struct Transaction {
    pub transactions_index: usize,
    pub name: String,
    pub weight: usize,
    pub sequence: usize,
    pub on_start: bool,
    pub on_stop: bool,
    pub function: TransactionFunction,
}
Expand description

An individual transaction within a Scenario.

Fields§

§transactions_index: usize

An index into Scenario.transaction, indicating which transaction this is.

§name: String

An optional name for the transaction, used when displaying metrics.

§weight: usize

An integer value that controls the frequency that this transaction will be run.

§sequence: usize

An integer value that controls when this transaction runs compared to other transactions in the same Scenario.

§on_start: bool

A flag indicating that this transaction runs when the user starts.

§on_stop: bool

A flag indicating that this transaction runs when the user stops.

§function: TransactionFunction

A required function that is executed each time this transaction runs.

Implementations§

source§

impl Transaction

source

pub fn new(function: TransactionFunction) -> Self

source

pub fn set_name(self, name: &str) -> Self

Set an optional name for the transaction, used when displaying metrics.

Individual requests can also be named using GooseRequestBuilder, or for GET requests with the GooseUser::get_named helper.

Example
use goose::prelude::*;

transaction!(my_transaction_function).set_name("foo");

async fn my_transaction_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("").await?;

    Ok(())
}
source

pub fn set_on_start(self) -> Self

Set an optional flag indicating that this transaction should be run when a user first starts. This could be used to log the user in, and so all subsequent transaction are done as a logged in user. A transaction 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 transactions can be sequenced and weighted. Sequences allow multiple on-start transactions to run in a controlled order. Weights allow on-start transactions to run multiple times when a user starts.

Example
use goose::prelude::*;

transaction!(my_on_start_function).set_on_start();

async fn my_on_start_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("").await?;

    Ok(())
}
source

pub fn set_on_stop(self) -> Self

Set an optional flag indicating that this transaction should be run when a user stops. This could be used to log a user out when the user finishes its load test. A transaction 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 transactions can be sequenced and weighted. Sequences allow multiple on-stop transactions to run in a controlled order. Weights allow on-stop transactions to run multiple times when a user stops.

Example
use goose::prelude::*;

transaction!(my_on_stop_function).set_on_stop();

async fn my_on_stop_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("").await?;

    Ok(())
}
source

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

Sets a weight on an individual transaction. The larger the value of weight, the more often it will be run in the Scenario. For example, if one transaction has a weight of 3 and another transaction has a weight of 1, the first transaction will run 3 times as often.

Example
use goose::prelude::*;

#[tokio::main]
async fn main() -> Result<(), GooseError> {
    transaction!(transaction_function).set_weight(3)?;

    Ok(())
}

async fn transaction_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("").await?;

    Ok(())
}
source

pub fn set_sequence(self, sequence: usize) -> Self

Defines the sequence value of an individual transactions. Transactions are run in order of their sequence value, so a transaction with a sequence value of 1 will run before a transaction with a sequence value of 2. Transactions with no sequence value (or a sequence value of 0) will run last, after all transactions with positive sequence values.

All transactions with the same sequence value will run in a random order. Transactions can be assigned both squence values and weights.

Examples

In this first example, the variable names indicate the order the transactions will be run in:

use goose::prelude::*;

let runs_first = transaction!(first_transaction_function).set_sequence(3);
let runs_second = transaction!(second_transaction_function).set_sequence(5835);
let runs_last = transaction!(third_transaction_function);

async fn first_transaction_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("1").await?;

    Ok(())
}

async fn second_transaction_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("2").await?;

    Ok(())
}

async fn third_transaction_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("3").await?;

    Ok(())
}

In the following example, the runs_first transactions 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 transactions being run in a random and weighted order:

use goose::prelude::*;

#[tokio::main]
async fn main() -> Result<(), GooseError> {
    let runs_first = transaction!(first_transaction_function).set_sequence(1).set_weight(2)?;
    let runs_second = transaction!(second_transaction_function_a).set_sequence(2);
    let also_runs_second = transaction!(second_transaction_function_b).set_sequence(2).set_weight(2)?;

    Ok(())
}

async fn first_transaction_function(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("1").await?;

    Ok(())
}

async fn second_transaction_function_a(user: &mut GooseUser) -> TransactionResult {
    let _goose = user.get("2a").await?;

    Ok(())
}

    async fn second_transaction_function_b(user: &mut GooseUser) -> TransactionResult {
      let _goose = user.get("2b").await?;

      Ok(())
    }

Trait Implementations§

source§

impl Clone for Transaction

source§

fn clone(&self) -> Transaction

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 Transaction

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,