Merge pull request #32606 from woocommerce/performance/merchant-view-coupons

Added new performance test to view coupons as merchant.
This commit is contained in:
Alejandro López Ariza 2022-05-10 14:37:12 +02:00 committed by GitHub
commit 56c8962722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 166 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: No entry needed because this change only added a new performance test.

View File

@ -0,0 +1,153 @@
import { sleep, check, group } from "k6";
import http from "k6/http";
import { Trend } from "k6/metrics";
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
import { findBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
import { base_url, think_time_min, think_time_max } from "../../config.js";
import {
htmlRequestHeader,
jsonAPIRequestHeader,
jsonRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
contentTypeRequestHeader,
commonPostRequestHeaders,
commonAPIGetRequestHeaders,
commonNonStandardHeaders,
} from "../../headers.js";
// Custom metrics to add to standard results output.
let postTypeCouponTrend = new Trend("wc_get_post_type_coupon");
let wcAdminNotesMainTrend = new Trend("wc_get_admin_notes_main");
let wcAdminNotesOtherTrend = new Trend("wc_get_admin_notes_other");
let wcAdminCESOptionsTrend = new Trend("wc_get_admin_options_ces");
let wpAdminHeartbeatTrend = new Trend("wc_post_wp_admin_heartbeat");
export function coupons() {
let response;
let api_x_wp_nonce;
let apiNonceHeader;
let heartbeat_nonce;
group("Coupons Page", function () {
var requestHeaders = Object.assign({},
htmlRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonNonStandardHeaders
);
response = http.get(`${base_url}/wp-admin/edit.php?post_type=shop_coupon`, {
headers: requestHeaders,
});
postTypeCouponTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
"body contains: 'Coupons' header": (response) =>
response.body.includes("Coupons</h1>"),
});
// Correlate nonce values for use in subsequent requests.
heartbeat_nonce = findBetween(
response.body,
'heartbeatSettings = {"nonce":"',
'"};'
);
api_x_wp_nonce = findBetween(
response.body,
'wp.apiFetch.createNonceMiddleware( "',
'" )'
);
// Create request header with nonce value for use in subsequent requests.
apiNonceHeader = {
"x-wp-nonce": `${api_x_wp_nonce}`,
};
});
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
group("Inbox Notes", function () {
var requestHeaders = Object.assign({},
jsonAPIRequestHeader,
commonRequestHeaders,
commonAPIGetRequestHeaders,
apiNonceHeader,
commonNonStandardHeaders
);
response = http.get(
`${base_url}/wp-json/wc-analytics/admin/notes?page=1&per_page=25&` +
`status=unactioned&type%5B0%5D=info&type%5B1%5D=marketing&type%5B2%5D=survey&type%5B3%5D=warning&` +
`orderby=date&order=desc&_locale=user`,
{
headers: requestHeaders,
}
);
wcAdminNotesMainTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
});
response = http.get(
`${base_url}/wp-json/wc-analytics/admin/notes?page=1&per_page=25&` +
`type=error%2Cupdate&status=unactioned&_locale=user`,
{
headers: requestHeaders,
}
);
wcAdminNotesOtherTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
});
});
group("CES Options", function () {
var requestHeaders = Object.assign({},
jsonAPIRequestHeader,
commonRequestHeaders,
commonAPIGetRequestHeaders,
apiNonceHeader,
commonNonStandardHeaders
);
response = http.get(
`${base_url}/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`,
{
headers: requestHeaders,
}
);
wcAdminCESOptionsTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
});
});
group("WP Admin Heartbeat", function () {
var requestHeaders = Object.assign({},
jsonRequestHeader,
commonRequestHeaders,
contentTypeRequestHeader,
commonPostRequestHeaders,
commonNonStandardHeaders
);
response = http.post(
`${base_url}/wp-admin/admin-ajax.php`,
`_nonce=${heartbeat_nonce}&action=heartbeat&has_focus=true&interval=15&screen_id=shop_coupon`,
{
headers: requestHeaders,
}
);
wpAdminHeartbeatTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
});
});
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
}
export default function () {
coupons();
}

View File

@ -7,6 +7,7 @@ import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js';
import { cartApplyCoupon } from '../requests/shopper/cart-apply-coupon.js'; import { cartApplyCoupon } from '../requests/shopper/cart-apply-coupon.js';
import { checkoutGuest } from '../requests/shopper/checkout-guest.js'; import { checkoutGuest } from '../requests/shopper/checkout-guest.js';
import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js';
import { coupons } from '../requests/merchant/coupons.js';
import { myAccount } from '../requests/shopper/my-account.js'; import { myAccount } from '../requests/shopper/my-account.js';
import { wpLogin } from '../requests/merchant/wp-login.js'; import { wpLogin } from '../requests/merchant/wp-login.js';
import { products } from '../requests/merchant/products.js'; import { products } from '../requests/merchant/products.js';
@ -111,6 +112,7 @@ export function merchantAllFlows() {
ordersSearch(); ordersSearch();
products(); products();
addProduct(); addProduct();
coupons();
} }
// Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login.
export function merchantHeartbeatFlow() { export function merchantHeartbeatFlow() {

View File

@ -7,6 +7,7 @@ import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js';
import { cartApplyCoupon } from '../requests/shopper/cart-apply-coupon.js'; import { cartApplyCoupon } from '../requests/shopper/cart-apply-coupon.js';
import { checkoutGuest } from '../requests/shopper/checkout-guest.js'; import { checkoutGuest } from '../requests/shopper/checkout-guest.js';
import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js';
import { coupons } from '../requests/merchant/coupons.js';
import { myAccount } from '../requests/shopper/my-account.js'; import { myAccount } from '../requests/shopper/my-account.js';
import { wpLogin } from '../requests/merchant/wp-login.js'; import { wpLogin } from '../requests/merchant/wp-login.js';
import { products } from '../requests/merchant/products.js'; import { products } from '../requests/merchant/products.js';
@ -101,6 +102,7 @@ export function merchantAllFlows() {
ordersSearch(); ordersSearch();
products(); products();
addProduct(); addProduct();
coupons();
} }
// Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login.
export function merchantHeartbeatFlow() { export function merchantHeartbeatFlow() {

View File

@ -6,6 +6,7 @@ import { cart } from '../requests/shopper/cart.js';
import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js'; import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js';
import { checkoutGuest } from '../requests/shopper/checkout-guest.js'; import { checkoutGuest } from '../requests/shopper/checkout-guest.js';
import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js';
import { coupons } from '../requests/merchant/coupons.js';
import { myAccount } from '../requests/shopper/my-account.js'; import { myAccount } from '../requests/shopper/my-account.js';
import { categoryPage } from '../requests/shopper/category-page.js'; import { categoryPage } from '../requests/shopper/category-page.js';
import { wpLogin } from '../requests/merchant/wp-login.js'; import { wpLogin } from '../requests/merchant/wp-login.js';
@ -127,4 +128,5 @@ export function allMerchantFlow() {
ordersSearch(); ordersSearch();
products(); products();
addProduct(); addProduct();
coupons();
} }

View File

@ -1,6 +1,7 @@
import { wpLogin } from '../requests/merchant/wp-login.js'; import { wpLogin } from '../requests/merchant/wp-login.js';
import { products } from '../requests/merchant/products.js'; import { products } from '../requests/merchant/products.js';
import { addProduct } from '../requests/merchant/add-product.js'; import { addProduct } from '../requests/merchant/add-product.js';
import { coupons } from '../requests/merchant/coupons.js';
import { orders } from '../requests/merchant/orders.js'; import { orders } from '../requests/merchant/orders.js';
import { ordersSearch } from '../requests/merchant/orders-search.js'; import { ordersSearch } from '../requests/merchant/orders-search.js';
import { homeWCAdmin } from '../requests/merchant/home-wc-admin.js'; import { homeWCAdmin } from '../requests/merchant/home-wc-admin.js';
@ -26,4 +27,5 @@ export function allMerchantFlow() {
ordersSearch(); ordersSearch();
products(); products();
addProduct(); addProduct();
coupons();
} }