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
Transaction
s and Transaction
names.
weighted_on_start_transactions: Vec<(usize, String)>
A vector of vectors of integers, controlling the sequence and order
on_start
Transaction
s 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
Transaction
s are run when the user first starts.
host: Option<String>
An optional default host to run this Scenario
against.
Implementations§
source§impl Scenario
impl Scenario
sourcepub fn new(name: &str) -> Self
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");
sourcepub fn register_transaction(self, transaction: Transaction) -> Self
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(())
}
sourcepub fn set_weight(self, weight: usize) -> Result<Self, GooseError>
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(())
}
sourcepub fn set_host(self, host: &str) -> Self
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");
sourcepub fn set_wait_time(
self,
min_wait: Duration,
max_wait: Duration
) -> Result<Self, GooseError>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for Scenario
impl Send for Scenario
impl Sync for Scenario
impl Unpin for Scenario
impl !UnwindSafe for Scenario
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
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>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.