Skip to content

Commit

Permalink
Merge pull request #45 from tag1consulting/update-0.16.0
Browse files Browse the repository at this point in the history
update to goose 0.16.0
  • Loading branch information
jeremyandrews authored May 1, 2022
2 parents aabeff8 + 6d2b392 commit ecae2f1
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 109 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.4.0 May 1, 2022
- update goose to [0.16](https://github.com/tag1consulting/goose/releases/tag/0.16.0)

## 0.3.1 November 2, 2021
- update goose to [0.15](https://github.com/tag1consulting/goose/releases/tag/0.15.0)

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "goose-eggs"
version = "0.3.1"
version = "0.4.0"
authors = ["Jeremy Andrews <[email protected]>"]
edition = "2018"
description = "Helpful in writing Goose load tests."
Expand All @@ -12,7 +12,7 @@ keywords = ["loadtesting", "performance", "web"]
license = "Apache-2.0"

[dependencies]
goose = "0.15"
goose = "0.16"
log = "0.4"
rand = "0.8"
regex = "1.5"
Expand Down
4 changes: 2 additions & 2 deletions examples/umami/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand::seq::SliceRandom;
use std::env;

/// Log into the website.
pub async fn log_in(user: &mut GooseUser) -> GooseTaskResult {
pub async fn log_in(user: &mut GooseUser) -> TransactionResult {
// Use ADMIN_USERNAME= to set custom admin username.
let admin_username = match env::var("ADMIN_USERNAME") {
Ok(username) => username,
Expand All @@ -29,7 +29,7 @@ pub async fn log_in(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load and edit a random article.
pub async fn edit_article(user: &mut GooseUser) -> GooseTaskResult {
pub async fn edit_article(user: &mut GooseUser) -> TransactionResult {
// First, load a random article.
let nodes = common::get_nodes(&common::ContentType::Article);
let article = nodes.choose(&mut rand::thread_rng());
Expand Down
35 changes: 17 additions & 18 deletions examples/umami/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,67 +34,59 @@ pub fn get_nodes(content_type: &ContentType) -> Vec<Node> {
ContentType::Article => {
vec![
Node {
nid: 10,
nid: 11,
url_en: "en/articles/give-it-a-go-and-grow-your-own-herbs",
url_es: "es/articles/prueba-y-cultiva-tus-propias-hierbas",
title_en: "Give it a go and grow your own herbs",
title_es: "Prueba y cultiva tus propias hierbas",
},
Node {
nid: 11,
nid: 12,
url_en: "en/articles/dairy-free-and-delicious-milk-chocolate",
url_es: "es/articles/delicioso-chocolate-sin-lactosa",
title_en: "Dairy-free and delicious milk chocolate",
title_es: "Delicioso chocolate sin lactosa",
},
Node {
nid: 12,
nid: 13,
url_en: "en/articles/the-real-deal-for-supermarket-savvy-shopping",
url_es: "es/articles/el-verdadeo-negocio-para-comprar-en-el-supermercado",
title_en: "The real deal for supermarket savvy shopping",
title_es: "El verdadero negocio para comprar en el supermercado",
},
Node {
nid: 13,
nid: 14,
url_en: "en/articles/the-umami-guide-to-our-favourite-mushrooms",
url_es: "es/articles/guia-umami-de-nuestras-setas-preferidas",
title_en: "The Umami guide to our favorite mushrooms",
title_es: "Guía Umami de nuestras setas preferidas",
},
Node {
nid: 14,
nid: 15,
url_en: "en/articles/lets-hear-it-for-carrots",
url_es: "es/articles/un-aplauso-para-las-zanahorias",
title_en: "Let&#039;s hear it for carrots",
title_es: "Un aplauso para las zanahorias",
},
Node {
nid: 15,
nid: 16,
url_en: "en/articles/baking-mishaps-our-troubleshooting-tips",
url_es:
"es/articles/percances-al-hornear-nuestros-consejos-para-solucionar-problemas",
url_es: "es/articles/percances-al-hornear-nuestros-consejos-para-solucionar-problemas",
title_en: "Baking mishaps - our troubleshooting tips",
title_es: "Percances al hornear - nuestros consejos para solucionar los problemas",
},
Node {
nid: 16,
nid: 17,
url_en: "en/articles/skip-the-spirits-with-delicious-mocktails",
url_es: "es/articles/salta-los-espiritus-con-deliciosos-cocteles-sin-alcohol",
title_en: "Skip the spirits with delicious mocktails",
title_es: "Salta los espíritus con deliciosos cócteles sin alcohol",
},
Node {
nid: 17,
url_en: "en/articles/give-your-oatmeal-the-ultimate-makeover",
url_es: "es/articles/dale-a-tu-avena-el-cambio-de-imagen-definitivo",
title_en: "Give your oatmeal the ultimate makeover",
title_es: "Dale a tu avena el cambio de imagen definitivo",
},
]
}
ContentType::BasicPage => {
vec![Node {
nid: 18,
nid: 19,
url_en: "en/about-umami",
url_es: "es/acerca-de-umami",
title_en: "About Umami",
Expand Down Expand Up @@ -166,6 +158,13 @@ pub fn get_nodes(content_type: &ContentType) -> Vec<Node> {
title_en: "Fiery chili sauce",
title_es: "Salsa de chile ardiente",
},
Node {
nid: 10,
url_en: "en/recipes/borscht-with-pork-ribs",
url_es: "es/recipes/borscht-con-costillas-de-cerdo",
title_en: "Borscht with pork ribs",
title_es: "Borscht con costillas de cerdo",
},
]
}
}
Expand Down Expand Up @@ -414,7 +413,7 @@ pub fn random_words(count: usize, english: bool) -> Vec<String> {

/// Anonymously load the contact form and POST feedback. The english boolean flag indicates
/// whether to load the English form or the Spanish form.
pub async fn anonymous_contact_form(user: &mut GooseUser, english: bool) -> GooseTaskResult {
pub async fn anonymous_contact_form(user: &mut GooseUser, english: bool) -> TransactionResult {
let contact_form_url = if english { "en/contact" } else { "es/contact" };
let goose = user.get(contact_form_url).await?;
let contact_page = goose_eggs::validate_and_load_static_assets(
Expand Down
20 changes: 10 additions & 10 deletions examples/umami/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::common;
use rand::seq::SliceRandom;

/// Load the front page in English and all static assets found on the page.
pub async fn front_page_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn front_page_en(user: &mut GooseUser) -> TransactionResult {
let goose = user.get("").await?;
goose_eggs::validate_and_load_static_assets(
user,
Expand All @@ -18,7 +18,7 @@ pub async fn front_page_en(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load recipe listing in English and all static assets found on the page.
pub async fn recipe_listing_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn recipe_listing_en(user: &mut GooseUser) -> TransactionResult {
let goose = user.get("en/recipes/").await?;
goose_eggs::validate_and_load_static_assets(
user,
Expand All @@ -31,7 +31,7 @@ pub async fn recipe_listing_en(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load a random recipe in English and all static assets found on the page.
pub async fn recipe_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn recipe_en(user: &mut GooseUser) -> TransactionResult {
let nodes = common::get_nodes(&common::ContentType::Recipe);
let recipe = nodes.choose(&mut rand::thread_rng());
let goose = user.get(recipe.unwrap().url_en).await?;
Expand All @@ -48,7 +48,7 @@ pub async fn recipe_en(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load article listing in English and all static assets found on the page.
pub async fn article_listing_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn article_listing_en(user: &mut GooseUser) -> TransactionResult {
let goose = user.get("en/articles/").await?;
goose_eggs::validate_and_load_static_assets(
user,
Expand All @@ -61,7 +61,7 @@ pub async fn article_listing_en(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load a random article in English and all static assets found on the page.
pub async fn article_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn article_en(user: &mut GooseUser) -> TransactionResult {
let nodes = common::get_nodes(&common::ContentType::Article);
let article = nodes.choose(&mut rand::thread_rng());
let goose = user.get(article.unwrap().url_en).await?;
Expand All @@ -78,7 +78,7 @@ pub async fn article_en(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load a random basic page in English and all static assets found on the page.
pub async fn basic_page_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn basic_page_en(user: &mut GooseUser) -> TransactionResult {
let nodes = common::get_nodes(&common::ContentType::BasicPage);
let page = nodes.choose(&mut rand::thread_rng());
let goose = user.get(page.unwrap().url_en).await?;
Expand All @@ -95,7 +95,7 @@ pub async fn basic_page_en(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load a random node by nid in English and all static assets found on the page.
pub async fn page_by_nid(user: &mut GooseUser) -> GooseTaskResult {
pub async fn page_by_nid(user: &mut GooseUser) -> TransactionResult {
// Randomly select a content type.
let content_types = vec![
common::ContentType::Article,
Expand Down Expand Up @@ -123,14 +123,14 @@ pub async fn page_by_nid(user: &mut GooseUser) -> GooseTaskResult {
}

/// Anonymously load the contact form in English and POST feedback.
pub async fn anonymous_contact_form_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn anonymous_contact_form_en(user: &mut GooseUser) -> TransactionResult {
common::anonymous_contact_form(user, true).await?;

Ok(())
}

// Pick a random word from the title of a random node and perform a search in English.
pub async fn search_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn search_en(user: &mut GooseUser) -> TransactionResult {
// Build a random three-word phrase taken from english words on the Umami website.
let search_words = common::random_words(3, true);
let search_phrase = search_words.join(" ");
Expand All @@ -153,7 +153,7 @@ pub async fn search_en(user: &mut GooseUser) -> GooseTaskResult {
}

/// Load category listing by a random term in English and all static assets found on the page.
pub async fn term_listing_en(user: &mut GooseUser) -> GooseTaskResult {
pub async fn term_listing_en(user: &mut GooseUser) -> TransactionResult {
let terms = common::get_terms();
let term = terms.choose(&mut rand::thread_rng());
let goose = user.get(term.unwrap().url_en).await?;
Expand Down
101 changes: 63 additions & 38 deletions examples/umami/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,76 +17,101 @@ use crate::spanish::*;
#[tokio::main]
async fn main() -> Result<(), GooseError> {
let _goose_metrics = GooseAttack::initialize()?
.register_taskset(
taskset!("Anonymous English user")
.register_scenario(
scenario!("Anonymous English user")
.set_weight(40)?
.set_wait_time(Duration::from_secs(0), Duration::from_secs(3))?
.register_task(task!(front_page_en).set_name("anon /").set_weight(2)?)
.register_task(task!(basic_page_en).set_name("anon /en/basicpage"))
.register_task(task!(article_listing_en).set_name("anon /en/articles/"))
.register_task(
task!(article_en)
.register_transaction(
transaction!(front_page_en)
.set_name("anon /")
.set_weight(2)?,
)
.register_transaction(transaction!(basic_page_en).set_name("anon /en/basicpage"))
.register_transaction(
transaction!(article_listing_en).set_name("anon /en/articles/"),
)
.register_transaction(
transaction!(article_en)
.set_name("anon /en/articles/%")
.set_weight(2)?,
)
.register_task(task!(recipe_listing_en).set_name("anon /en/recipes/"))
.register_task(
task!(recipe_en)
.register_transaction(transaction!(recipe_listing_en).set_name("anon /en/recipes/"))
.register_transaction(
transaction!(recipe_en)
.set_name("anon /en/recipes/%")
.set_weight(4)?,
)
.register_task(task!(page_by_nid).set_name("anon /node/%nid"))
.register_task(
task!(term_listing_en)
.register_transaction(transaction!(page_by_nid).set_name("anon /node/%nid"))
.register_transaction(
transaction!(term_listing_en)
.set_name("anon /en term")
.set_weight(2)?,
)
.register_task(task!(search_en).set_name("anon /en/search"))
.register_task(task!(anonymous_contact_form_en).set_name("anon /en/contact")),
.register_transaction(transaction!(search_en).set_name("anon /en/search"))
.register_transaction(
transaction!(anonymous_contact_form_en).set_name("anon /en/contact"),
),
)
.register_taskset(
taskset!("Anonymous Spanish user")
.register_scenario(
scenario!("Anonymous Spanish user")
.set_weight(9)?
.set_wait_time(Duration::from_secs(0), Duration::from_secs(3))?
.register_task(task!(front_page_es).set_name("anon /es/").set_weight(2)?)
.register_task(task!(basic_page_es).set_name("anon /es/basicpage"))
.register_task(task!(article_listing_es).set_name("anon /es/articles/"))
.register_task(
task!(article_es)
.register_transaction(
transaction!(front_page_es)
.set_name("anon /es/")
.set_weight(2)?,
)
.register_transaction(transaction!(basic_page_es).set_name("anon /es/basicpage"))
.register_transaction(
transaction!(article_listing_es).set_name("anon /es/articles/"),
)
.register_transaction(
transaction!(article_es)
.set_name("anon /es/articles/%")
.set_weight(2)?,
)
.register_task(task!(recipe_listing_es).set_name("anon /es/recipes/"))
.register_task(
task!(recipe_es)
.register_transaction(transaction!(recipe_listing_es).set_name("anon /es/recipes/"))
.register_transaction(
transaction!(recipe_es)
.set_name("anon /es/recipes/%")
.set_weight(4)?,
)
.register_task(
task!(term_listing_es)
.register_transaction(
transaction!(term_listing_es)
.set_name("anon /es term")
.set_weight(2)?,
)
.register_task(task!(search_es).set_name("anon /es/search"))
.register_task(task!(anonymous_contact_form_es).set_name("anon /es/contact")),
.register_transaction(transaction!(search_es).set_name("anon /es/search"))
.register_transaction(
transaction!(anonymous_contact_form_es).set_name("anon /es/contact"),
),
)
.register_taskset(
taskset!("Admin user")
.register_scenario(
scenario!("Admin user")
.set_weight(1)?
.set_wait_time(Duration::from_secs(0), Duration::from_secs(3))?
.register_task(task!(log_in).set_on_start().set_name("auth /en/user/login"))
.register_task(task!(front_page_en).set_name("auth /").set_weight(2)?)
.register_task(task!(article_listing_en).set_name("auth /en/articles/"))
.register_task(
task!(edit_article)
.register_transaction(
transaction!(log_in)
.set_on_start()
.set_name("auth /en/user/login"),
)
.register_transaction(
transaction!(front_page_en)
.set_name("auth /")
.set_weight(2)?,
)
.register_transaction(
transaction!(article_listing_en).set_name("auth /en/articles/"),
)
.register_transaction(
transaction!(edit_article)
.set_name("auth /en/node/%/edit")
.set_weight(2)?,
),
)
.set_default(GooseDefault::Host, "https://drupal-9.ddev.site/")?
.execute()
.await?
.print();
.await?;

Ok(())
}
Loading

0 comments on commit ecae2f1

Please sign in to comment.