Skip to content

Commit

Permalink
convert client to user
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyandrews committed Jun 26, 2020
1 parent 7776528 commit 8347d24
Show file tree
Hide file tree
Showing 18 changed files with 604 additions and 612 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Changelog

## 0.7.6-dev
## 0.8.0-dev
- properly subtract previous statistic when handling `set_failure()` and `set_success()`
- detect and track redirects in `GooseRawRequest`
- `--sticky-follow` makes redirect of GooseClient base_url sticky, affecting subsequent requests
- changed `GooseClient` to `GooseUser`

## 0.7.5 June 10, 2020
- store actual URL requested in GooseRawRequest
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "goose"
version = "0.7.6-dev"
version = "0.8.0-dev"
authors = ["Jeremy Andrews <[email protected]>"]
edition = "2018"
description = "A load testing tool inspired by Locust."
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ heading:

```toml
[dependencies]
goose = "^0.7"
goose = "^0.8"
```

At this point it's possible to compile all dependencies, though the
Expand All @@ -47,9 +47,9 @@ resulting binary only displays "Hello, world!":
```
$ cargo run
Updating crates.io index
Downloaded goose v0.7.5
Downloaded goose v0.8.0
...
Compiling goose v0.7.5
Compiling goose v0.8.0
Compiling loadtest v0.1.0 (/home/jandrews/devel/rust/loadtest)
Finished dev [unoptimized + debuginfo] target(s) in 52.97s
Running `target/debug/loadtest`
Expand Down Expand Up @@ -165,11 +165,11 @@ load tests. For example, pass the `-h` flag to the `simple` example,
`cargo run --example simple -- -h`:

```
client 0.7.5
client 0.8.0
CLI options available when launching a Goose load test
USAGE:
simple [FLAGS] [OPTIONS]
8 simple [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
Expand Down Expand Up @@ -305,7 +305,7 @@ feature in the `dependencies` section of your `Cargo.toml`, for example:

```toml
[dependencies]
goose = { version = "^0.7", features = ["gaggle"] }
goose = { version = "^0.8", features = ["gaggle"] }
```

### Goose Manager
Expand Down
50 changes: 25 additions & 25 deletions examples/drupal_loadtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ fn main() {
}

/// View the front page.
async fn drupal_loadtest_front_page(client: &GooseClient) {
let mut response = client.get("/").await;
async fn drupal_loadtest_front_page(user: &GooseUser) {
let mut response = user.get("/").await;

// Grab some static assets from the front page.
match response.response {
Expand All @@ -97,36 +97,36 @@ async fn drupal_loadtest_front_page(client: &GooseClient) {
}
}
for index in 0..urls.len() {
client.get_named(&urls[index], "static asset").await;
user.get_named(&urls[index], "static asset").await;
}
}
Err(e) => {
eprintln!("failed to parse front page: {}", e);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
}
},
Err(e) => {
eprintln!("unexpected error when loading front page: {}", e);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
}
}
}

/// View a node from 1 to 10,000, created by preptest.sh.
async fn drupal_loadtest_node_page(client: &GooseClient) {
async fn drupal_loadtest_node_page(user: &GooseUser) {
let nid = rand::thread_rng().gen_range(1, 10_000);
let _response = client.get(format!("/node/{}", &nid).as_str()).await;
let _response = user.get(format!("/node/{}", &nid).as_str()).await;
}

/// View a profile from 2 to 5,001, created by preptest.sh.
async fn drupal_loadtest_profile_page(client: &GooseClient) {
async fn drupal_loadtest_profile_page(user: &GooseUser) {
let uid = rand::thread_rng().gen_range(2, 5_001);
let _response = client.get(format!("/user/{}", &uid).as_str()).await;
let _response = user.get(format!("/user/{}", &uid).as_str()).await;
}

/// Log in.
async fn drupal_loadtest_login(client: &GooseClient) {
let mut response = client.get("/user").await;
async fn drupal_loadtest_login(user: &GooseUser) {
let mut response = user.get("/user").await;
match response.response {
Ok(r) => {
match r.text().await {
Expand All @@ -136,7 +136,7 @@ async fn drupal_loadtest_login(client: &GooseClient) {
Some(f) => f,
None => {
eprintln!("no form_build_id on page: /user page");
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
return;
}
};
Expand All @@ -151,13 +151,13 @@ async fn drupal_loadtest_login(client: &GooseClient) {
("form_id", "user_login"),
("op", "Log+in"),
];
let request_builder = client.goose_post("/user").await;
let _response = client.goose_send(request_builder.form(&params), None).await;
let request_builder = user.goose_post("/user").await;
let _response = user.goose_send(request_builder.form(&params), None).await;
// @TODO: verify that we actually logged in.
}
Err(e) => {
eprintln!("unexpected error when loading /user page: {}", e);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
}
}
}
Expand All @@ -167,11 +167,11 @@ async fn drupal_loadtest_login(client: &GooseClient) {
}

/// Post a comment.
async fn drupal_loadtest_post_comment(client: &GooseClient) {
async fn drupal_loadtest_post_comment(user: &GooseUser) {
let nid: i32 = rand::thread_rng().gen_range(1, 10_000);
let node_path = format!("node/{}", &nid);
let comment_path = format!("/comment/reply/{}", &nid);
let mut response = client.get(&node_path).await;
let mut response = user.get(&node_path).await;
match response.response {
Ok(r) => {
match r.text().await {
Expand All @@ -182,7 +182,7 @@ async fn drupal_loadtest_post_comment(client: &GooseClient) {
Some(f) => f,
None => {
eprintln!("no form_build_id found on {}", &node_path);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
return;
}
};
Expand All @@ -192,7 +192,7 @@ async fn drupal_loadtest_post_comment(client: &GooseClient) {
Some(f) => f,
None => {
eprintln!("no form_token found on {}", &node_path);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
return;
}
};
Expand All @@ -202,7 +202,7 @@ async fn drupal_loadtest_post_comment(client: &GooseClient) {
Some(f) => f,
None => {
eprintln!("no form_id found on {}", &node_path);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
return;
}
};
Expand All @@ -218,8 +218,8 @@ async fn drupal_loadtest_post_comment(client: &GooseClient) {
("form_id", &form_id[1]),
("op", "Save"),
];
let request_builder = client.goose_post(&comment_path).await;
let mut response = client.goose_send(request_builder.form(&params), None).await;
let request_builder = user.goose_post(&comment_path).await;
let mut response = user.goose_send(request_builder.form(&params), None).await;
match response.response {
Ok(r) => match r.text().await {
Ok(html) => {
Expand All @@ -228,15 +228,15 @@ async fn drupal_loadtest_post_comment(client: &GooseClient) {
"no comment showed up after posting to {}",
&comment_path
);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
}
}
Err(e) => {
eprintln!(
"unexpected error when posting to {}: {}",
&comment_path, e
);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
}
},
// Goose will catch this error.
Expand All @@ -245,7 +245,7 @@ async fn drupal_loadtest_post_comment(client: &GooseClient) {
}
Err(e) => {
eprintln!("unexpected error when loading {} page: {}", &node_path, e);
client.set_failure(&mut response.request);
user.set_failure(&mut response.request);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
taskset!("WebsiteUser")
// After each task runs, sleep randomly from 5 to 15 seconds.
.set_wait_time(5, 15)
// This task only runs one time when the client first starts.
// This task only runs one time when the user first starts.
.register_task(task!(website_login).set_on_start())
// These next two tasks run repeatedly as long as the load test is running.
.register_task(task!(website_index))
Expand All @@ -35,22 +35,22 @@ fn main() {
.execute();
}

/// Demonstrates how to log in when a client starts. We flag this task as an
/// Demonstrates how to log in when a user starts. We flag this task as an
/// on_start task when registering it above. This means it only runs one time
/// per client, when the client thread first starts.
async fn website_login(client: &GooseClient) {
let request_builder = client.goose_post("/login").await;
/// per user, when the user thread first starts.
async fn website_login(user: &GooseUser) {
let request_builder = user.goose_post("/login").await;
// https://docs.rs/reqwest/*/reqwest/blocking/struct.RequestBuilder.html#method.form
let params = [("username", "test_user"), ("password", "")];
let _response = client.goose_send(request_builder.form(&params), None).await;
let _response = user.goose_send(request_builder.form(&params), None).await;
}

/// A very simple task that simply loads the front page.
async fn website_index(client: &GooseClient) {
let _response = client.get("/").await;
async fn website_index(user: &GooseUser) {
let _response = user.get("/").await;
}

/// A very simple task that simply loads the about page.
async fn website_about(client: &GooseClient) {
let _response = client.get("/about/").await;
async fn website_about(user: &GooseUser) {
let _response = user.get("/about/").await;
}
Loading

0 comments on commit 8347d24

Please sign in to comment.