[−][src]Struct goose::goose::GooseClient
An individual client state, repeatedly running all GooseTasks in a specific GooseTaskSet.
Fields
task_sets_index: usize
An index into the internal GooseTest.task_sets
vector, indicating which GooseTaskSet is running.
client: Client
A reqwest.blocking.client
instance (@TODO: async).
default_host: Option<String>
Optional global host, can be overridden per-task-set or via the cli.
task_set_host: Option<String>
Optional per-task-set .host.
min_wait: usize
Minimum amount of time to sleep after running a task.
max_wait: usize
Maximum amount of time to sleep after running a task.
config: GooseConfiguration
A local copy of the global GooseConfiguration.
weighted_clients_index: usize
An index into the internal `GooseTest.weighted_clients, indicating which weighted GooseTaskSet is running.
mode: GooseClientMode
The current run mode of this client, see enum GooseClientMode
.
weighted_on_start_tasks: Vec<Vec<usize>>
A weighted list of all tasks that run when the client first starts.
weighted_tasks: Vec<Vec<usize>>
A weighted list of all tasks that this client runs once started.
weighted_bucket: usize
A pointer into which sequenced bucket the client is currently running tasks from.
weighted_bucket_position: usize
A pointer of which task within the current sequenced bucket is currently running.
weighted_on_stop_tasks: Vec<Vec<usize>>
A weighted list of all tasks that run when the client stops.
task_request_name: Option<String>
Optional name of all requests made within the current task.
request_name: Option<String>
Optional name of all requests made within the current task.
previous_path: Option<String>
Store the previous url.
previous_method: Option<GooseMethod>
Store the previous url.
previous_request_name: Option<String>
Store the optional request_name allowing tasks to toggle success/failure.
was_success: bool
Store if the previous request was a success (false for failure).
requests: HashMap<String, GooseRequest>
Optional statistics collected about all requests made by this client.
load_test_hash: u64
Load test hash.
Implementations
impl GooseClient
[src]
pub fn new(
counter: usize,
task_sets_index: usize,
default_host: Option<String>,
task_set_host: Option<String>,
min_wait: usize,
max_wait: usize,
configuration: &GooseConfiguration,
load_test_hash: u64
) -> Self
[src]
counter: usize,
task_sets_index: usize,
default_host: Option<String>,
task_set_host: Option<String>,
min_wait: usize,
max_wait: usize,
configuration: &GooseConfiguration,
load_test_hash: u64
) -> Self
Create a new client state.
pub fn set_request_name(&mut self, name: &str) -> &mut Self
[src]
Sets a name for the next request made.
One example use case of this is to group together requests to different URLs in the statistics that don't need to be split out, perhaps because they're all the same type of page.
Examples
In this example, the request will show up as "GET foo":
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(get_function); /// A very simple task that makes a GET request. async fn get_function(client: &mut GooseClient) { let _response = client.set_request_name("foo").get("/path/to/foo"); }
In this example, the first request will show up in the statistics as "GET foo", and the second request will show up as "GET /path/to/foo".
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(get_function); /// A very simple task that makes a GET request. async fn get_function(client: &mut GooseClient) { let _response = client.set_request_name("foo").get("/path/to/foo").await; let _response = client.get("/path/to/foo").await; }
pub fn set_mode(&mut self, mode: GooseClientMode)
[src]
Sets the current run mode of this client.
pub fn build_url(&mut self, path: &str) -> String
[src]
A helper that pre-pends a hostname to the path. For example, if you pass in /foo
and --host
is set to http://127.0.0.1
it will return http://127.0.0.1/foo
.
Respects per-GooseTaskSet
host
configuration, global GooseAttack
host
configuration, and --host
CLI configuration option.
If path
is passed in with a hard-coded host, this will be used instead.
Host is defined in the following order:
- If
path
includes the host, use this - Otherwise, if
--host
is defined, use this - Otherwise, if
GooseTaskSet.host
is defined, use this - Otherwise, use global
GooseAttack.host
.
pub async fn get<'_, '_>(&'_ mut self, path: &'_ str) -> Result<Response, Error>
[src]
A helper to make a GET
request of a path and collect relevant statistics.
Automatically prepends the correct host.
(If you need to set headers, change timeouts, or otherwise make use of the
reqwest::RequestBuilder
object, you can instead call goose_get
which returns a RequestBuilder, then
call goose_send
to invoke the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(get_function); /// A very simple task that makes a GET request. async fn get_function(client: &mut GooseClient) { let _response = client.get("/path/to/foo/"); }
pub async fn post<'_, '_>(
&'_ mut self,
path: &'_ str,
body: String
) -> Result<Response, Error>
[src]
&'_ mut self,
path: &'_ str,
body: String
) -> Result<Response, Error>
A helper to make a POST
request of a path and collect relevant statistics.
Automatically prepends the correct host.
(If you need to set headers, change timeouts, or otherwise make use of the
reqwest::RequestBuilder
object, you can instead call goose_post
which returns a RequestBuilder, then
call goose_send
to invoke the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(post_function); /// A very simple task that makes a POST request. async fn post_function(client: &mut GooseClient) { let _response = client.post("/path/to/foo/", "BODY BEING POSTED".to_string()); }
pub async fn head<'_, '_>(
&'_ mut self,
path: &'_ str
) -> Result<Response, Error>
[src]
&'_ mut self,
path: &'_ str
) -> Result<Response, Error>
A helper to make a HEAD
request of a path and collect relevant statistics.
Automatically prepends the correct host.
(If you need to set headers, change timeouts, or otherwise make use of the
reqwest::RequestBuilder
object, you can instead call goose_head
which returns a RequestBuilder, then
call goose_send
to invoke the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(head_function); /// A very simple task that makes a HEAD request. async fn head_function(client: &mut GooseClient) { let _response = client.head("/path/to/foo/"); }
pub async fn delete<'_, '_>(
&'_ mut self,
path: &'_ str
) -> Result<Response, Error>
[src]
&'_ mut self,
path: &'_ str
) -> Result<Response, Error>
A helper to make a DELETE
request of a path and collect relevant statistics.
Automatically prepends the correct host.
(If you need to set headers, change timeouts, or otherwise make use of the
reqwest::RequestBuilder
object, you can instead call goose_delete
which returns a RequestBuilder,
then call goose_send
to invoke the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(delete_function); /// A very simple task that makes a DELETE request. async fn delete_function(client: &mut GooseClient) { let _response = client.delete("/path/to/foo/"); }
pub fn goose_get(&mut self, path: &str) -> RequestBuilder
[src]
Prepends the correct host on the path, then prepares a
reqwest::RequestBuilder
object for making a GET
request.
(You must then call goose_send
on this object to actually execute the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(get_function); /// A simple task that makes a GET request, exposing the Reqwest /// request builder. async fn get_function(client: &mut GooseClient) { let request_builder = client.goose_get("/path/to/foo"); let response = client.goose_send(request_builder); }
pub fn goose_post(&mut self, path: &str) -> RequestBuilder
[src]
Prepends the correct host on the path, then prepares a
reqwest::RequestBuilder
object for making a POST
request.
(You must then call goose_send
on this object to actually execute the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(post_function); /// A simple task that makes a POST request, exposing the Reqwest /// request builder. async fn post_function(client: &mut GooseClient) { let request_builder = client.goose_post("/path/to/foo"); let response = client.goose_send(request_builder); }
pub fn goose_head(&mut self, path: &str) -> RequestBuilder
[src]
Prepends the correct host on the path, then prepares a
reqwest::RequestBuilder
object for making a HEAD
request.
(You must then call goose_send
on this object to actually execute the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(head_function); /// A simple task that makes a HEAD request, exposing the Reqwest /// request builder. async fn head_function(client: &mut GooseClient) { let request_builder = client.goose_head("/path/to/foo"); let response = client.goose_send(request_builder); }
pub fn goose_put(&mut self, path: &str) -> RequestBuilder
[src]
Prepends the correct host on the path, then prepares a
reqwest::RequestBuilder
object for making a PUT
request.
(You must then call goose_send
on this object to actually execute the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(put_function); /// A simple task that makes a PUT request, exposing the Reqwest /// request builder. async fn put_function(client: &mut GooseClient) { let request_builder = client.goose_put("/path/to/foo"); let response = client.goose_send(request_builder); }
pub fn goose_patch(&mut self, path: &str) -> RequestBuilder
[src]
Prepends the correct host on the path, then prepares a
reqwest::RequestBuilder
object for making a PATCH
request.
(You must then call goose_send
on this object to actually execute the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(patch_function); /// A simple task that makes a PUT request, exposing the Reqwest /// request builder. async fn patch_function(client: &mut GooseClient) { let request_builder = client.goose_patch("/path/to/foo"); let response = client.goose_send(request_builder); }
pub fn goose_delete(&mut self, path: &str) -> RequestBuilder
[src]
Prepends the correct host on the path, then prepares a
reqwest::RequestBuilder
object for making a DELETE
request.
(You must then call goose_send
on this object to actually execute the request.)
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(delete_function); /// A simple task that makes a DELETE request, exposing the Reqwest /// request builder. async fn delete_function(client: &mut GooseClient) { let request_builder = client.goose_delete("/path/to/foo"); let response = client.goose_send(request_builder); }
pub async fn goose_send<'_>(
&'_ mut self,
request_builder: RequestBuilder
) -> Result<Response, Error>
[src]
&'_ mut self,
request_builder: RequestBuilder
) -> Result<Response, Error>
Builds the provided
reqwest::RequestBuilder
object and then executes the response. If statistics are being displayed, it
also captures request statistics.
It is possible to build and execute a RequestBuilder
object directly with
Reqwest without using this helper function, but then Goose is unable to capture
statistics.
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(get_function); /// A simple task that makes a GET request, exposing the Reqwest /// request builder. async fn get_function(client: &mut GooseClient) { let request_builder = client.goose_get("/path/to/foo"); let response = client.goose_send(request_builder); }
pub fn set_success(&mut self)
[src]
Manually mark a request as a success.
By default, Goose will consider any response with a 2xx status code as a success. It may be valid in your test for a non-2xx HTTP status code to be returned.
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(get_function); /// A simple task that makes a GET request. async fn get_function(client: &mut GooseClient) { let response = client.get("/404").await; match &response { Ok(r) => { // We expect a 404 here. if r.status() == 404 { client.set_success(); } }, Err(_) => (), } }
pub fn set_failure(&mut self)
[src]
Manually mark a request as a failure.
By default, Goose will consider any response with a 2xx status code as a success. You may require more advanced logic, in which a 2xx status code is actually a failure.
Example
use goose::goose::{GooseTask, GooseClient}; use goose::task; // Needed to wrap and store async functions. use std::boxed::Box; let mut task = task!(loadtest_index_page); async fn loadtest_index_page(client: &mut GooseClient) { let response = client.set_request_name("index").get("/").await; // Extract the response Result. match response { Ok(r) => { // We only need to check pages that returned a success status code. if r.status().is_success() { match r.text().await { Ok(text) => { // If the expected string doesn't exist, this page load // was a failure. if !text.contains("this string must exist") { client.set_failure(); } } // Empty page, this is a failure. Err(_) => client.set_failure(), } } }, // Invalid response, this is already a failure. Err(_) => (), } }
Trait Implementations
impl Clone for GooseClient
[src]
fn clone(&self) -> GooseClient
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for GooseClient
[src]
Auto Trait Implementations
impl !RefUnwindSafe for GooseClient
impl Send for GooseClient
impl Sync for GooseClient
impl Unpin for GooseClient
impl !UnwindSafe for GooseClient
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,