Skip to content

Commit

Permalink
Merge pull request #16 from vrobert78/counters
Browse files Browse the repository at this point in the history
Counters & Pauses in the reference scenario
  • Loading branch information
shyim authored Jan 21, 2025
2 parents de98dd1 + a93cab4 commit be8fe93
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 125 deletions.
20 changes: 14 additions & 6 deletions example-api.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { productChangePrice, fetchBearerToken, productImport, productChangeStocks, useCredentials } from "./helpers/api.js";
import { Counter } from 'k6/metrics';
import { Trend } from 'k6/metrics';

let fetchBearerTokenRT = new Trend('response_time_fetchBearerToken');
let fetchBearerTokenCounter = new Counter('counter_fetchBearerToken');

let APIProductImportRT = new Trend('response_time_API_ProductImport');
let APIproductChangePrice = new Trend('response_time_API_productChangePrice');
let APIproductChangeStocks = new Trend('response_time_API_productChangeStocks');
let APIProductImportCounter = new Counter('counter_API_ProductImport');

let APIproductChangePriceRT = new Trend('response_time_API_productChangePrice');
let APIproductChangePriceCounter = new Counter('counter_API_productChangePrice');

let APIproductChangeStocksRT = new Trend('response_time_API_productChangeStocks');
let APIproductChangeStocksCounter = new Counter('counter_API_productChangeStocks');

export function setup() {
const token = fetchBearerToken(fetchBearerTokenRT);
const token = fetchBearerToken(fetchBearerTokenRT, fetchBearerTokenCounter);

return { token };
}

export default (data) => {
useCredentials(data.token);
productImport(APIProductImportRT, 20);
productChangePrice(APIproductChangePrice, 20);
productChangeStocks(APIproductChangeStocks, 20);
productImport(APIProductImportRT, APIProductImportCounter, 20);
productChangePrice(APIproductChangePriceRT, APIproductChangePriceCounter, 20);
productChangeStocks(APIproductChangeStocksRT, APIproductChangeStocksCounter, 20);
}
32 changes: 20 additions & 12 deletions example-big-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,38 @@ import {
import { Counter } from 'k6/metrics';
import { Trend } from 'k6/metrics';

let orderCounter = new Counter('orders');
let StoreFrontRT = new Trend('response_time_StoreFront');
let SearchPageRT = new Trend('response_time_SearchPage');
let NavigationPageRT = new Trend('response_time_NavigationPage');
let StoreFrontCounter = new Counter('counter_StoreFront');

let ProductDetailPageRT = new Trend('response_time_ProductDetailPage');
let guestRegisterPageRT = new Trend('response_time_guestRegister');
let ProductDetailCounter = new Counter('counter_ProductDetail');

let CartPageRT = new Trend('response_time_CartPage');
let CartPageCounter = new Counter('counter_CartPage');

let ConfirmPageRT = new Trend('response_time_ConfirmPage');
let ConfirmPageCounter = new Counter('counter_ConfirmPage');

let placeOrderRT = new Trend('response_time_placeOrder');
let orderCounter = new Counter('counter_orders');

let accountRegisterRT = new Trend('response_time_accountRegister');
let accountLoginRT = new Trend('response_time_accountLogin');
let accountDashboardRT = new Trend('response_time_accountDashboard');
let accountRegisterCounter = new Counter('counter_accountRegister');

let addProductToCartRT = new Trend('response_time_addProductToCart');
let addProductToCartCounter = new Counter('counter_addProductToCart');

let CartInfoRT = new Trend('response_time_CartInfo');
let fetchBearerTokenRT = new Trend('response_time_fetchBearerToken');
let CartInfoCounter = new Counter('counter_CartInfo');

export default function () {
visitStorefront(StoreFrontRT);
accountRegister(accountRegisterRT);
visitStorefront(StoreFrontRT, StoreFrontCounter);
accountRegister(accountRegisterRT, accountRegisterCounter);
// add 10 products to cart
for (let i = 0; i < 10; i++) {
addProductToCart(addProductToCartRT, CartInfoRT, visitProductDetailPage(ProductDetailPageRT).id);
addProductToCart(addProductToCartRT, addProductToCartCounter, CartInfoRT, CartInfoCounter, visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter).id);
}
visitCartPage(CartPageRT);
visitConfirmPage(ConfirmPageRT);
visitCartPage(CartPageRT, CartPageCounter);
visitConfirmPage(ConfirmPageRT, ConfirmPageCounter);
placeOrder(orderCounter, placeOrderRT);
}
32 changes: 20 additions & 12 deletions example-fast-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,35 @@ import {
import { Counter } from 'k6/metrics';
import { Trend } from 'k6/metrics';

let orderCounter = new Counter('orders');
let StoreFrontRT = new Trend('response_time_StoreFront');
let SearchPageRT = new Trend('response_time_SearchPage');
let NavigationPageRT = new Trend('response_time_NavigationPage');
let StoreFrontCounter = new Counter('counter_StoreFront');

let ProductDetailPageRT = new Trend('response_time_ProductDetailPage');
let guestRegisterPageRT = new Trend('response_time_guestRegister');
let ProductDetailCounter = new Counter('counter_ProductDetail');

let CartPageRT = new Trend('response_time_CartPage');
let CartPageCounter = new Counter('counter_CartPage');

let ConfirmPageRT = new Trend('response_time_ConfirmPage');
let ConfirmPageCounter = new Counter('counter_ConfirmPage');

let placeOrderRT = new Trend('response_time_placeOrder');
let orderCounter = new Counter('counter_orders');

let accountRegisterRT = new Trend('response_time_accountRegister');
let accountLoginRT = new Trend('response_time_accountLogin');
let accountDashboardRT = new Trend('response_time_accountDashboard');
let accountRegisterCounter = new Counter('counter_accountRegister');

let addProductToCartRT = new Trend('response_time_addProductToCart');
let addProductToCartCounter = new Counter('counter_addProductToCart');

let CartInfoRT = new Trend('response_time_CartInfo');
let fetchBearerTokenRT = new Trend('response_time_fetchBearerToken');
let CartInfoCounter = new Counter('counter_CartInfo');

export default function () {
visitStorefront(StoreFrontRT);
accountRegister(accountRegisterRT);
addProductToCart(addProductToCartRT, CartInfoRT, visitProductDetailPage(ProductDetailPageRT).id);
visitCartPage(CartPageRT);
visitConfirmPage(ConfirmPageRT);
visitStorefront(StoreFrontRT, StoreFrontCounter);
accountRegister(accountRegisterRT, accountRegisterCounter);
addProductToCart(addProductToCartRT, addProductToCartCounter, CartInfoRT, CartInfoCounter, visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter).id);
visitCartPage(CartPageRT, CartPageCounter);
visitConfirmPage(ConfirmPageRT, ConfirmPageCounter);
placeOrder(orderCounter, placeOrderRT);
}
32 changes: 20 additions & 12 deletions example-guest-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,35 @@ import {
import { Counter } from 'k6/metrics';
import { Trend } from 'k6/metrics';

let orderCounter = new Counter('orders');
let StoreFrontRT = new Trend('response_time_StoreFront');
let SearchPageRT = new Trend('response_time_SearchPage');
let NavigationPageRT = new Trend('response_time_NavigationPage');
let StoreFrontCounter = new Counter('counter_StoreFront');

let ProductDetailPageRT = new Trend('response_time_ProductDetailPage');
let ProductDetailCounter = new Counter('counter_ProductDetail');

let guestRegisterPageRT = new Trend('response_time_guestRegister');
let guestRegisterPageCounter = new Counter('counter_guestRegisterPage');

let CartPageRT = new Trend('response_time_CartPage');
let CartPageCounter = new Counter('counter_CartPage');

let ConfirmPageRT = new Trend('response_time_ConfirmPage');
let ConfirmPageCounter = new Counter('counter_ConfirmPage');

let placeOrderRT = new Trend('response_time_placeOrder');
let accountRegisterRT = new Trend('response_time_accountRegister');
let accountLoginRT = new Trend('response_time_accountLogin');
let accountDashboardRT = new Trend('response_time_accountDashboard');
let orderCounter = new Counter('counter_orders');

let addProductToCartRT = new Trend('response_time_addProductToCart');
let addProductToCartCounter = new Counter('counter_addProductToCart');

let CartInfoRT = new Trend('response_time_CartInfo');
let fetchBearerTokenRT = new Trend('response_time_fetchBearerToken');
let CartInfoCounter = new Counter('counter_CartInfo');

export default function () {
visitStorefront(StoreFrontRT);
guestRegister(guestRegisterPageRT);
addProductToCart(addProductToCartRT, CartInfoRT, visitProductDetailPage(ProductDetailPageRT).id);
visitCartPage(CartPageRT);
visitConfirmPage(ConfirmPageRT);
visitStorefront(StoreFrontRT, StoreFrontCounter);
guestRegister(guestRegisterPageRT, guestRegisterPageCounter);
addProductToCart(addProductToCartRT, addProductToCartCounter, CartInfoRT, CartInfoCounter, visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter).id);
visitCartPage(CartPageRT, CartPageCounter);
visitConfirmPage(ConfirmPageRT, ConfirmPageCounter);
placeOrder(orderCounter, placeOrderRT);
}
53 changes: 35 additions & 18 deletions example-multi-scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,64 @@ export const options = {
},
};

let orderCounter = new Counter('orders');
let StoreFrontRT = new Trend('response_time_StoreFront');
let StoreFrontCounter = new Counter('counter_StoreFront');

let SearchPageRT = new Trend('response_time_SearchPage');
let SearchPageCounter = new Counter('counter_SearchPage');

let NavigationPageRT = new Trend('response_time_NavigationPage');
let NavigationPageCounter = new Counter('counter_NavigationPage');

let ProductDetailPageRT = new Trend('response_time_ProductDetailPage');
let guestRegisterPageRT = new Trend('response_time_guestRegister');
let CartPageRT = new Trend('response_time_CartPage');
let ConfirmPageRT = new Trend('response_time_ConfirmPage');
let ProductDetailCounter = new Counter('counter_ProductDetail');

let placeOrderRT = new Trend('response_time_placeOrder');
let orderCounter = new Counter('counter_orders');

let accountRegisterRT = new Trend('response_time_accountRegister');
let accountLoginRT = new Trend('response_time_accountLogin');
let accountDashboardRT = new Trend('response_time_accountDashboard');
let accountRegisterCounter = new Counter('counter_accountRegister');

let addProductToCartRT = new Trend('response_time_addProductToCart');
let addProductToCartCounter = new Counter('counter_addProductToCart');

let CartInfoRT = new Trend('response_time_CartInfo');
let CartInfoCounter = new Counter('counter_CartInfo');

let fetchBearerTokenRT = new Trend('response_time_fetchBearerToken');
let fetchBearerTokenCounter = new Counter('counter_fetchBearerToken');

let APIProductImportRT = new Trend('response_time_API_ProductImport');
let APIproductChangePrice = new Trend('response_time_API_productChangePrice');
let APIproductChangeStocks = new Trend('response_time_API_productChangeStocks');
let APIProductImportCounter = new Counter('counter_API_ProductImport');

let APIproductChangePriceRT = new Trend('response_time_API_productChangePrice');
let APIproductChangePriceCounter = new Counter('counter_API_productChangePrice');

let APIproductChangeStocksRT = new Trend('response_time_API_productChangeStocks');
let APIproductChangeStocksCounter = new Counter('counter_API_productChangeStocks');

export function browseOnly() {
visitStorefront(StoreFrontRT);
visitSearchPage(SearchPageRT);
visitNavigationPage(NavigationPageRT);
visitProductDetailPage(ProductDetailPageRT);
visitStorefront(StoreFrontRT, StoreFrontCounter);
visitSearchPage(SearchPageRT, SearchPageCounter);
visitNavigationPage(NavigationPageRT, NavigationPageCounter);
visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter);
}

export function fastBuy() {
addProductToCart(addProductToCartRT, CartInfoRT, visitProductDetailPage(ProductDetailPageRT).id);
accountRegister(accountRegisterRT);
addProductToCart(addProductToCartRT, addProductToCartCounter, CartInfoRT, CartInfoCounter, visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter).id);
accountRegister(accountRegisterRT, accountRegisterCounter);
placeOrder(orderCounter, placeOrderRT);
}

export function setup() {
const token = fetchBearerToken(fetchBearerTokenRT);
const token = fetchBearerToken(fetchBearerTokenRT, fetchBearerTokenCounter);

return { token };
}

export function importer(data) {
useCredentials(data.token);
productImport(APIProductImportRT);
productChangePrice(APIproductChangePrice);
productChangeStocks(APIproductChangeStocks);
productImport(APIProductImportRT, APIProductImportCounter);
productChangePrice(APIproductChangePriceRT, APIproductChangePriceCounter);
productChangeStocks(APIproductChangeStocksRT, APIproductChangeStocksCounter);
}
55 changes: 35 additions & 20 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,52 @@ import {
import { Counter } from 'k6/metrics';
import { Trend } from 'k6/metrics';

let orderCounter = new Counter('orders');
let StoreFrontRT = new Trend('response_time_StoreFront');
let StoreFrontCounter = new Counter('counter_StoreFront');

let SearchPageRT = new Trend('response_time_SearchPage');
let SearchPageCounter = new Counter('counter_SearchPage');

let NavigationPageRT = new Trend('response_time_NavigationPage');
let NavigationPageCounter = new Counter('counter_NavigationPage');

let ProductDetailPageRT = new Trend('response_time_ProductDetailPage');
let guestRegisterPageRT = new Trend('response_time_guestRegister');
let ProductDetailCounter = new Counter('counter_ProductDetail');

let CartPageRT = new Trend('response_time_CartPage');
let CartPageCounter = new Counter('counter_CartPage');

let ConfirmPageRT = new Trend('response_time_ConfirmPage');
let ConfirmPageCounter = new Counter('counter_ConfirmPage');

let placeOrderRT = new Trend('response_time_placeOrder');
let orderCounter = new Counter('counter_orders');

let accountRegisterRT = new Trend('response_time_accountRegister');
let accountLoginRT = new Trend('response_time_accountLogin');
let accountDashboardRT = new Trend('response_time_accountDashboard');
let accountRegisterCounter = new Counter('counter_accountRegister');

let addProductToCartRT = new Trend('response_time_addProductToCart');
let addProductToCartCounter = new Counter('counter_addProductToCart');

let CartInfoRT = new Trend('response_time_CartInfo');
let CartInfoCounter = new Counter('counter_CartInfo');

export default function () {
visitStorefront(StoreFrontRT);
visitSearchPage(SearchPageRT);
visitNavigationPage(NavigationPageRT);
accountRegister(accountRegisterRT);
visitNavigationPage(NavigationPageRT);
addProductToCart(addProductToCartRT, CartInfoRT, visitProductDetailPage(ProductDetailPageRT).id);
visitSearchPage(SearchPageRT);
visitNavigationPage(NavigationPageRT);
visitSearchPage(SearchPageRT);
visitNavigationPage(NavigationPageRT);
addProductToCart(addProductToCartRT, CartInfoRT, visitProductDetailPage(ProductDetailPageRT).id);
visitNavigationPage(NavigationPageRT);
visitNavigationPage(NavigationPageRT);
addProductToCart(addProductToCartRT, CartInfoRT, visitProductDetailPage(ProductDetailPageRT).id);
visitCartPage(CartPageRT);
visitConfirmPage(ConfirmPageRT);
visitStorefront(StoreFrontRT, StoreFrontCounter);
visitSearchPage(SearchPageRT, SearchPageCounter);
visitNavigationPage(NavigationPageRT, NavigationPageCounter);
accountRegister(accountRegisterRT, accountRegisterCounter);
visitNavigationPage(NavigationPageRT, NavigationPageCounter);
addProductToCart(addProductToCartRT, addProductToCartCounter, CartInfoRT, CartInfoCounter, visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter).id);
visitSearchPage(SearchPageRT, SearchPageCounter);
visitNavigationPage(NavigationPageRT, NavigationPageCounter);
visitSearchPage(SearchPageRT, SearchPageCounter);
visitNavigationPage(NavigationPageRT, NavigationPageCounter);
addProductToCart(addProductToCartRT, addProductToCartCounter, CartInfoRT, CartInfoCounter, visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter).id);
visitNavigationPage(NavigationPageRT, NavigationPageCounter);
visitNavigationPage(NavigationPageRT, NavigationPageCounter);
addProductToCart(addProductToCartRT, addProductToCartCounter, CartInfoRT, CartInfoCounter, visitProductDetailPage(ProductDetailPageRT, ProductDetailCounter).id);
visitCartPage(CartPageRT, CartPageCounter);
visitConfirmPage(ConfirmPageRT, ConfirmPageCounter);
placeOrder(orderCounter, placeOrderRT);
}
Loading

0 comments on commit be8fe93

Please sign in to comment.