[][src]Struct goose::goose::GooseClient

pub struct GooseClient {
    pub task_sets_index: usize,
    pub client: Client,
    pub default_host: Option<String>,
    pub task_set_host: Option<String>,
    pub min_wait: usize,
    pub max_wait: usize,
    pub config: GooseConfiguration,
    pub weighted_clients_index: usize,
    pub mode: GooseClientMode,
    pub weighted_on_start_tasks: Vec<Vec<usize>>,
    pub weighted_tasks: Vec<Vec<usize>>,
    pub weighted_bucket: usize,
    pub weighted_bucket_position: usize,
    pub weighted_on_stop_tasks: Vec<Vec<usize>>,
    pub task_request_name: Option<String>,
    pub request_name: Option<String>,
    pub previous_path: Option<String>,
    pub previous_method: Option<Method>,
    pub previous_request_name: Option<String>,
    pub was_success: bool,
    pub requests: HashMap<String, GooseRequest>,
}

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>

The global GooseState host.

task_set_host: Option<String>

The GooseTaskSet.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<Method>

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.

Methods

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
) -> Self
[src]

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":

    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".

    let _response = client.set_request_name("foo").get("/path/to/foo");
    let _response = client.get("/path/to/foo");

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 GooseState 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 GooseState.host.

pub 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

    let _response = client.get("/path/to/foo");

pub fn post(&mut self, path: &str, body: String) -> Result<Response, Error>[src]

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

    let _response = client.post("/path/to/foo", "BODY BEING POSTED");

pub fn head(&mut self, path: &str) -> Result<Response, Error>[src]

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

    let _response = client.head("/path/to/foo");

pub fn delete(&mut self, path: &str) -> Result<Response, Error>[src]

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

    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

    let request_builder = client.goose_get("/path/to/foo");
    let response = self.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

    let request_builder = client.goose_post("/path/to/foo");
    let response = self.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

    let request_builder = client.goose_head("/path/to/foo");
    let response = self.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

    let request_builder = client.goose_put("/login");

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

    let request_builder = client.goose_patch("/path/to/foo");

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

    let request_builder = client.goose_delete("/path/to/foo");

pub fn goose_send(
    &mut self,
    request_builder: RequestBuilder
) -> Result<Response, Error>
[src]

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

    let request_builder = client.goose_get("/path/to/foo");
    let response = self.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

    let response = client.get("/404");
    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

fn loadtest_index(client: &mut GooseClient) {
    let response = client.set_request_name("index").get("/");
    // 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() {
                    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]

impl Debug for GooseClient[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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