From f6b5913d328bf5e76b8e3ab3161f68848329ac1e Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 12 May 2023 16:25:51 -0300 Subject: [PATCH] Add HPOS specific k6 test suite (#37665) * Add HPOS specific k6 test suite * revert unintntional partial revert of #37719 --------- Co-authored-by: Ron Rennick --- .../changelog/fix-265-add-k6-hpos-baseline | 4 + .../requests/merchant/add-order.js | 486 +++++++++++++++--- .../requests/merchant/add-product.js | 466 +++++++++-------- .../requests/merchant/home-wc-admin.js | 234 +++++---- .../performance/requests/merchant/orders.js | 197 +++---- .../performance/tests/hpos-baseline-load.js | 303 +++++++++++ 6 files changed, 1203 insertions(+), 487 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-265-add-k6-hpos-baseline create mode 100644 plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js diff --git a/plugins/woocommerce/changelog/fix-265-add-k6-hpos-baseline b/plugins/woocommerce/changelog/fix-265-add-k6-hpos-baseline new file mode 100644 index 00000000000..bbd5512f833 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-265-add-k6-hpos-baseline @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add HPOS specific k6 test suite diff --git a/plugins/woocommerce/tests/performance/requests/merchant/add-order.js b/plugins/woocommerce/tests/performance/requests/merchant/add-order.js index a39788bae2b..a7c303e4228 100644 --- a/plugins/woocommerce/tests/performance/requests/merchant/add-order.js +++ b/plugins/woocommerce/tests/performance/requests/merchant/add-order.js @@ -74,7 +74,7 @@ if ( cot_status === true ) { const date = new Date(); const order_date = date.toJSON().slice( 0, 10 ); -export function addOrder() { +export function addOrder( includeTests = {} ) { let response; let ajax_nonce_add_meta; let wpnonce; @@ -87,6 +87,15 @@ export function addOrder() { let api_x_wp_nonce; let apiNonceHeader; let heartbeat_nonce; + let includedTests = Object.assign( { + create: true, + heartbeat: true, + open: true, + other: true, + update: true, + }, + includeTests + ); group( 'Add Order', function () { const requestHeaders = Object.assign( @@ -170,75 +179,430 @@ export function addOrder() { sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); - group( 'All Orders - Other Requests', function () { - const requestHeaders = Object.assign( - {}, - jsonAPIRequestHeader, - commonRequestHeaders, - commonAPIGetRequestHeaders, - apiNonceHeader, - commonNonStandardHeaders - ); + if ( includedTests.other ) { + group( 'All Orders - Other Requests', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); - response = http.get( - `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, - { - headers: requestHeaders, - tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + response = http.get( + `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, + } + ); + 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, + tags: { name: 'Merchant - wc-analytics/admin/notes?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + + response = http.get( + `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, + { + headers: requestHeaders, + tags: { + name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', + }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + } ); + } + + if ( includedTests.heartbeat ) { + group( 'WP Admin Heartbeat', function () { + const 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_order`, + { + headers: requestHeaders, + tags: { name: 'Merchant - action=heartbeat' }, + } + ); + 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, - tags: { name: 'Merchant - wc-analytics/admin/notes?' }, + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + } + + if ( includedTests.create ) { + group( 'Create New Order', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + contentTypeRequestHeader, + commonNonStandardHeaders + ); + + const date = new Date(); + const order_date = date.toJSON().slice( 0, 10 ); + + const orderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wp_original_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'editpost' ], + [ 'auto_draft', '1' ], //no + [ 'closedpostboxesnonce', `${ closed_postboxes_nonce }` ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'meta-box-order-nonce', `${ meta_box_order_nonce }` ], + [ 'metakeyinput', '' ], + [ 'metakeyselect', '%23NONE%23' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-pending' ], + [ 'original_post_status', 'auto-draft' ], + [ 'original_post_title', '' ], + [ 'originalaction', 'editpost' ], + [ 'post_ID', `${ post_id }` ], + [ 'post_author', '1' ], + [ 'post_status', 'auto-draft' ], + [ 'post_title', '%2COrder' ], + [ 'post_type', 'shop_order' ], + [ 'referredby', '' ], + [ 'samplepermalinknonce', `${ sample_permalink_nonce }` ], + [ 'save', 'Create' ], + [ 'user_ID', '1' ], + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + const cotOrderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'edit_order' ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'metakeyinput', '' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-pending' ], + [ 'original_order_status', 'auto-draft' ], + [ 'post_status', 'auto-draft' ], + [ 'post_title', 'Order' ], + [ 'referredby', '' ], + [ 'save', 'Create' ], + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + if ( cot_status === true ) { + admin_update_order = `${ admin_update_order_base }&id=${ hpos_post_id }`; + admin_update_order_params = cotOrderParams.toString(); + } else { + admin_update_order = admin_update_order_base; + admin_update_order_params = orderParams.toString(); } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + + response = http.post( + `${ base_url }/wp-admin/${ admin_update_order }`, + admin_update_order_params.toString(), + { + headers: requestHeaders, + tags: { name: 'Merchant - Create New Order' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Edit order' header": ( response ) => + response.body.includes( `${ admin_open_order_assert }` ), + "body contains: 'Order updated' confirmation": ( response ) => + response.body.includes( `${ admin_created_order_assert }` ), + } ); } ); - response = http.get( - `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, - { - headers: requestHeaders, - tags: { - name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', - }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - } ); - } ); + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + } - group( 'WP Admin Heartbeat', function () { - const requestHeaders = Object.assign( - {}, - jsonRequestHeader, - commonRequestHeaders, - contentTypeRequestHeader, - commonPostRequestHeaders, - commonNonStandardHeaders - ); + if ( includedTests.open ) { + group( 'Open Order', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonNonStandardHeaders + ); - response = http.post( - `${ base_url }/wp-admin/admin-ajax.php`, - `_nonce=${ heartbeat_nonce }&action=heartbeat&has_focus=true&interval=15&screen_id=shop_order`, - { - headers: requestHeaders, - tags: { name: 'Merchant - action=heartbeat' }, + if ( cot_status === true ) { + admin_open_order_base = `${ admin_update_order_base }&id=${ hpos_post_id }`; + } else { + admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`; } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + + response = http.get( + `${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`, + { + headers: requestHeaders, + tags: { name: 'Merchant - Open Order' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Edit order' header": ( response ) => + response.body.includes( `${ admin_open_order_assert }` ), + } ); } ); - } ); + + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + } + + if ( includedTests.update ) { + group( 'Update Order', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + contentTypeRequestHeader, + commonNonStandardHeaders + ); + + const orderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wp_original_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'editpost' ], + [ 'closedpostboxesnonce', `${ closed_postboxes_nonce }` ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'meta-box-order-nonce', `${ meta_box_order_nonce }` ], + [ 'metakeyinput', '' ], + [ 'metakeyselect', '%23NONE%23' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-completed' ], + [ 'original_post_status', 'wc-pending' ], + [ 'original_post_title', '' ], + [ 'originalaction', 'editpost' ], + [ 'post_ID', `${ post_id }` ], + [ 'post_author', '1' ], + [ 'post_status', 'pending' ], + [ 'post_title', '%2COrder' ], + [ 'post_type', 'shop_order' ], + [ 'referredby', '' ], + [ 'samplepermalinknonce', `${ sample_permalink_nonce }` ], + [ 'save', 'Update' ], + [ 'user_ID', '1' ], + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + const cotOrderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'edit_order' ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'metakeyinput', '' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-completed' ], + [ 'original_order_status', 'pending' ], + [ 'post_status', 'pending' ], + [ 'post_title', 'Order' ], + [ 'referredby', '' ], + [ 'save', 'Save' ], + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + if ( cot_status === true ) { + admin_update_order_id = `${ admin_update_order_base }&id=${ hpos_post_id }`; + admin_update_order_params = cotOrderParams.toString(); + } else { + admin_update_order_params = orderParams.toString(); + admin_update_order_id = `${ admin_open_order_base }`; + } + + response = http.post( + `${ base_url }/wp-admin/${ admin_update_order_id }`, + admin_update_order_params.toString(), + { + headers: requestHeaders, + tags: { name: 'Merchant - Update Existing Order Status' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Order updated' confirmation": ( response ) => + response.body.includes( `${ admin_update_order_assert }` ), + } ); + } ); + } sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); @@ -584,7 +948,7 @@ export function addOrder() { response.body.includes( `${ admin_update_order_assert }` ), } ); } ); -} +}; export default function () { addOrder(); diff --git a/plugins/woocommerce/tests/performance/requests/merchant/add-product.js b/plugins/woocommerce/tests/performance/requests/merchant/add-product.js index 44d9f7dcb56..67c66b9c892 100644 --- a/plugins/woocommerce/tests/performance/requests/merchant/add-product.js +++ b/plugins/woocommerce/tests/performance/requests/merchant/add-product.js @@ -33,7 +33,7 @@ import { allRequestHeader, } from '../../headers.js'; -export function addProduct() { +export function addProduct( includeTests = {} ) { let response; let heartbeat_nonce; let ajax_nonce_add_meta; @@ -46,6 +46,14 @@ export function addProduct() { let post_id; let api_x_wp_nonce; let apiNonceHeader; + let includedTests = Object.assign( { + heartbeat: true, + other: true, + permalink: true, + update: true, + }, + includeTests + ); group( 'Add New Product', function () { const requestHeaders = Object.assign( @@ -130,242 +138,250 @@ export function addProduct() { sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); - group( 'Add New Product - Other Requests', function () { - const requestHeaders = Object.assign( - {}, - jsonAPIRequestHeader, - commonRequestHeaders, - commonAPIGetRequestHeaders, - apiNonceHeader, - commonNonStandardHeaders - ); + if ( includedTests.other ) { + group( 'Add New Product - Other Requests', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); - response = http.get( - `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, - { - headers: requestHeaders, - tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + response = http.get( + `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, + } + ); + 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, + tags: { name: 'Merchant - wc-analytics/admin/notes?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + + response = http.get( + `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, + { + headers: requestHeaders, + tags: { + name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', + }, + } + ); + 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, - tags: { name: 'Merchant - wc-analytics/admin/notes?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - } ); + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + } - response = http.get( - `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, - { - headers: requestHeaders, - tags: { - name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', + if ( includedTests.heartbeat ) { + group( 'Autosave heartbeat', function () { + const requestHeaders = Object.assign( + {}, + commonNonStandardHeaders, + jsonAPIRequestHeader, + commonPostRequestHeaders, + commonRequestHeaders + ); + + response = http.post( + `${ base_url }/wp-admin/admin-ajax.php`, + { + _nonce: `${ heartbeat_nonce }`, + action: 'heartbeat', + 'data%5Bwp-refresh-post-lock%5D%5Bpost_id%5D': `${ post_id }`, + 'data%5Bwp_autosave%5D%5B_wpnonce%5D': `${ wpnonce }`, + 'data%5Bwp_autosave%5D%5Bauto_draft%5D': '1', + 'data%5Bwp_autosave%5D%5Bcatslist%5D': '', + 'data%5Bwp_autosave%5D%5Bcomment_status%5D': 'open', + 'data%5Bwp_autosave%5D%5Bcontent%5D': '', + 'data%5Bwp_autosave%5D%5Bexcerpt%5D': '', + 'data%5Bwp_autosave%5D%5Bpost_author%5D': '1', + 'data%5Bwp_autosave%5D%5Bpost_id%5D': `${ post_id }`, + 'data%5Bwp_autosave%5D%5Bpost_title%5D': `${ add_product_title }`, + 'data%5Bwp_autosave%5D%5Bpost_type%5D': 'product', + has_focus: 'true', + interval: '15', + screen_id: 'product', }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + { + headers: requestHeaders, + tags: { name: 'Merchant - action=heartbeat autosave' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); } ); - } ); + } - sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + if ( includedTests.permalink ) { + group( 'Sample Permalink', function () { + const requestHeaders = Object.assign( + {}, + commonNonStandardHeaders, + allRequestHeader, + contentTypeRequestHeader, + commonPostRequestHeaders + ); - group( 'Autosave heartbeat', function () { - const requestHeaders = Object.assign( - {}, - commonNonStandardHeaders, - jsonAPIRequestHeader, - commonPostRequestHeaders, - commonRequestHeaders - ); - - response = http.post( - `${ base_url }/wp-admin/admin-ajax.php`, - { - _nonce: `${ heartbeat_nonce }`, - action: 'heartbeat', - 'data%5Bwp-refresh-post-lock%5D%5Bpost_id%5D': `${ post_id }`, - 'data%5Bwp_autosave%5D%5B_wpnonce%5D': `${ wpnonce }`, - 'data%5Bwp_autosave%5D%5Bauto_draft%5D': '1', - 'data%5Bwp_autosave%5D%5Bcatslist%5D': '', - 'data%5Bwp_autosave%5D%5Bcomment_status%5D': 'open', - 'data%5Bwp_autosave%5D%5Bcontent%5D': '', - 'data%5Bwp_autosave%5D%5Bexcerpt%5D': '', - 'data%5Bwp_autosave%5D%5Bpost_author%5D': '1', - 'data%5Bwp_autosave%5D%5Bpost_id%5D': `${ post_id }`, - 'data%5Bwp_autosave%5D%5Bpost_title%5D': `${ add_product_title }`, - 'data%5Bwp_autosave%5D%5Bpost_type%5D': 'product', - has_focus: 'true', - interval: '15', - screen_id: 'product', - }, - { - headers: requestHeaders, - tags: { name: 'Merchant - action=heartbeat autosave' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + response = http.post( + `${ base_url }/wp-admin/admin-ajax.php`, + { + action: 'sample-permalink', + new_title: `${ add_product_title }`, + post_id: `${ post_id }`, + samplepermalinknonce: `${ sample_permalink_nonce }`, + }, + { + headers: requestHeaders, + tags: { name: 'Merchant - action=sample-permalink' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Permalink:'": ( response ) => + response.body.includes( 'Permalink:' ), + } ); } ); - } ); - group( 'Sample Permalink', function () { - const requestHeaders = Object.assign( - {}, - commonNonStandardHeaders, - allRequestHeader, - contentTypeRequestHeader, - commonPostRequestHeaders - ); + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + } - response = http.post( - `${ base_url }/wp-admin/admin-ajax.php`, - { - action: 'sample-permalink', - new_title: `${ add_product_title }`, - post_id: `${ post_id }`, - samplepermalinknonce: `${ sample_permalink_nonce }`, - }, - { - headers: requestHeaders, - tags: { name: 'Merchant - action=sample-permalink' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - "body contains: 'Permalink:'": ( response ) => - response.body.includes( 'Permalink:' ), + if ( includedTests.update ) { + group( 'Update New Product', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + contentTypeRequestHeader, + commonNonStandardHeaders + ); + + const productParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ + '_ajax_nonce-add-product_cat', + `${ ajax_nonce_add_product_cat }`, + ], + [ '_backorders', 'no' ], + [ '_button_text', '' ], + [ '_download_expiry', '' ], + [ '_download_limit', '' ], + [ '_height', '' ], + [ '_length', '' ], + [ '_low_stock_amount', '' ], + [ '_original_stock', '0' ], + [ '_product_url', '' ], + [ '_purchase_note', '' ], + [ '_regular_price', `${ add_product_regular_price }` ], + [ '_sale_price', '' ], + [ '_sale_price_dates_from', '' ], + [ '_sale_price_dates_to', '' ], + [ '_sku', '' ], + [ '_stock', '0' ], + [ '_stock_status', 'instock' ], + [ '_thumbnail_id', '-1' ], + [ '_visibility', 'visible' ], + [ '_weight', '' ], + [ '_width', '' ], + [ '_wp_http_referer', '' ], + [ '_wp_original_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'aa', '2021' ], + [ 'action', 'editpost' ], + [ 'attribute_taxonomy', '' ], + [ 'auto_draft', '' ], + [ 'closedpostboxesnonce', `${ closed_postboxes_nonce }` ], + [ 'comment_status', 'open' ], + [ 'content', '' ], + [ 'cur_aa', '2021' ], + [ 'cur_hh', '15' ], + [ 'cur_jj', '09' ], + [ 'cur_mm', '07' ], + [ 'cur_mn', '48' ], + [ 'current_featured', 'no' ], + [ 'current_visibility', 'visible' ], + [ 'excerpt', '' ], + [ 'hh', '15' ], + [ 'hidden_aa', '2021' ], + [ 'hidden_hh', '15' ], + [ 'hidden_jj', '09' ], + [ 'hidden_mm', '07' ], + [ 'hidden_mn', '48' ], + [ 'hidden_post_password', '' ], + [ 'hidden_post_status', 'draft' ], + [ 'hidden_post_visibility', 'public' ], + [ 'jj', '09' ], + [ 'menu_order', '0' ], + [ 'meta-box-order-nonce', `${ meta_box_order_nonce }` ], + [ 'metakeyinput', '' ], + [ 'metakeyselect', '%2523NONE%2523' ], + [ 'metavalue', '' ], + [ 'mm', '07' ], + [ 'mn', '48' ], + [ 'newproduct_cat', 'New%2520category%2520name' ], + [ 'newproduct_cat_parent', '-1' ], + [ 'newtag%255Bproduct_tag%255D', '' ], + [ 'original_post_status', 'auto-draft' ], + [ 'original_post_title', '' ], + [ 'original_publish', 'Publish' ], + [ 'originalaction', 'editpost' ], + [ 'post_ID', `${ post_id }` ], + [ 'post_author', '1' ], + [ 'post_name', '' ], + [ 'post_password', '' ], + [ 'post_status', 'draft' ], + [ 'post_title', `${ add_product_title }` ], + [ 'post_type', 'product' ], + [ 'product-type', 'simple' ], + [ 'product_image_gallery', '' ], + [ 'product_shipping_class', '-1' ], + [ 'publish', 'Publish' ], + [ 'referredby', '' ], + [ 'samplepermalinknonce', `${ sample_permalink_nonce }` ], + [ 'ss', '12' ], + [ 'tax_input%255Bproduct_cat%255D%255B%255D', '0' ], + [ 'tax_input%255Bproduct_tag%255D', '' ], + [ 'user_ID', '1' ], + [ 'visibility', 'public' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + [ 'wp-preview', '' ], + ] ); + + response = http.post( + `${ base_url }/wp-admin/post.php`, + productParams.toString(), + { + headers: requestHeaders, + tags: { name: 'Merchant - Update New Product' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Edit product' header": ( response ) => + response.body.includes( 'Edit product' ), + "body contains: 'Product published' confirmation": ( response ) => + response.body.includes( 'Product published.' ), + } ); } ); - } ); - - sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); - - group( 'Update New Product', function () { - const requestHeaders = Object.assign( - {}, - htmlRequestHeader, - commonRequestHeaders, - commonGetRequestHeaders, - contentTypeRequestHeader, - commonNonStandardHeaders - ); - - const productParams = new URLSearchParams( [ - [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], - [ - '_ajax_nonce-add-product_cat', - `${ ajax_nonce_add_product_cat }`, - ], - [ '_backorders', 'no' ], - [ '_button_text', '' ], - [ '_download_expiry', '' ], - [ '_download_limit', '' ], - [ '_height', '' ], - [ '_length', '' ], - [ '_low_stock_amount', '' ], - [ '_original_stock', '0' ], - [ '_product_url', '' ], - [ '_purchase_note', '' ], - [ '_regular_price', `${ add_product_regular_price }` ], - [ '_sale_price', '' ], - [ '_sale_price_dates_from', '' ], - [ '_sale_price_dates_to', '' ], - [ '_sku', '' ], - [ '_stock', '0' ], - [ '_stock_status', 'instock' ], - [ '_thumbnail_id', '-1' ], - [ '_visibility', 'visible' ], - [ '_weight', '' ], - [ '_width', '' ], - [ '_wp_http_referer', '' ], - [ '_wp_original_http_referer', '' ], - [ '_wpnonce', `${ wpnonce }` ], - [ 'aa', '2021' ], - [ 'action', 'editpost' ], - [ 'attribute_taxonomy', '' ], - [ 'auto_draft', '' ], - [ 'closedpostboxesnonce', `${ closed_postboxes_nonce }` ], - [ 'comment_status', 'open' ], - [ 'content', '' ], - [ 'cur_aa', '2021' ], - [ 'cur_hh', '15' ], - [ 'cur_jj', '09' ], - [ 'cur_mm', '07' ], - [ 'cur_mn', '48' ], - [ 'current_featured', 'no' ], - [ 'current_visibility', 'visible' ], - [ 'excerpt', '' ], - [ 'hh', '15' ], - [ 'hidden_aa', '2021' ], - [ 'hidden_hh', '15' ], - [ 'hidden_jj', '09' ], - [ 'hidden_mm', '07' ], - [ 'hidden_mn', '48' ], - [ 'hidden_post_password', '' ], - [ 'hidden_post_status', 'draft' ], - [ 'hidden_post_visibility', 'public' ], - [ 'jj', '09' ], - [ 'menu_order', '0' ], - [ 'meta-box-order-nonce', `${ meta_box_order_nonce }` ], - [ 'metakeyinput', '' ], - [ 'metakeyselect', '%2523NONE%2523' ], - [ 'metavalue', '' ], - [ 'mm', '07' ], - [ 'mn', '48' ], - [ 'newproduct_cat', 'New%2520category%2520name' ], - [ 'newproduct_cat_parent', '-1' ], - [ 'newtag%255Bproduct_tag%255D', '' ], - [ 'original_post_status', 'auto-draft' ], - [ 'original_post_title', '' ], - [ 'original_publish', 'Publish' ], - [ 'originalaction', 'editpost' ], - [ 'post_ID', `${ post_id }` ], - [ 'post_author', '1' ], - [ 'post_name', '' ], - [ 'post_password', '' ], - [ 'post_status', 'draft' ], - [ 'post_title', `${ add_product_title }` ], - [ 'post_type', 'product' ], - [ 'product-type', 'simple' ], - [ 'product_image_gallery', '' ], - [ 'product_shipping_class', '-1' ], - [ 'publish', 'Publish' ], - [ 'referredby', '' ], - [ 'samplepermalinknonce', `${ sample_permalink_nonce }` ], - [ 'ss', '12' ], - [ 'tax_input%255Bproduct_cat%255D%255B%255D', '0' ], - [ 'tax_input%255Bproduct_tag%255D', '' ], - [ 'user_ID', '1' ], - [ 'visibility', 'public' ], - [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], - [ 'wp-preview', '' ], - ] ); - - response = http.post( - `${ base_url }/wp-admin/post.php`, - productParams.toString(), - { - headers: requestHeaders, - tags: { name: 'Merchant - Update New Product' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - "body contains: 'Edit product' header": ( response ) => - response.body.includes( 'Edit product' ), - "body contains: 'Product published' confirmation": ( response ) => - response.body.includes( 'Product published.' ), - } ); - } ); + } sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); } diff --git a/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js b/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js index a488e8a8153..1cf8bbb6d98 100644 --- a/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js +++ b/plugins/woocommerce/tests/performance/requests/merchant/home-wc-admin.js @@ -23,10 +23,18 @@ import { commonNonStandardHeaders, } from '../../headers.js'; -export function homeWCAdmin() { +export function homeWCAdmin( includeTests = {} ) { let response; let api_x_wp_nonce; let apiNonceHeader; + let includedTests = Object.assign( { + orders: true, + other: true, + products: true, + reviews: true, + }, + includeTests + ); group( 'WC Home Page', function () { const requestHeaders = Object.assign( @@ -62,123 +70,131 @@ export function homeWCAdmin() { sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); - group( 'WC Admin - Other Requests', function () { - const requestHeaders = Object.assign( - {}, - jsonAPIRequestHeader, - commonRequestHeaders, - commonAPIGetRequestHeaders, - apiNonceHeader, - commonNonStandardHeaders - ); + if ( includedTests.other ) { + group( 'WC Admin - Other Requests', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); - response = http.get( - `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, - { - headers: requestHeaders, - tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + response = http.get( + `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, + } + ); + 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, + tags: { name: 'Merchant - wc-analytics/admin/notes?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + + response = http.get( + `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, + { + headers: requestHeaders, + tags: { + name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', + }, + } + ); + 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, - tags: { name: 'Merchant - wc-analytics/admin/notes?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + if ( includedTests.orders ) { + group( 'Orders Activity', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); + + response = http.get( + `${ base_url }/wp-json/wc-analytics/orders?page=1&per_page=1&status%5B0%5D=processing&` + + `status%5B1%5D=on-hold&_fields%5B0%5D=id&_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-analytics/orders?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); } ); + } - response = http.get( - `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, - { - headers: requestHeaders, - tags: { - name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', - }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + if ( includedTests.reviews ) { + group( 'Reviews Activity', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); + + response = http.get( + `${ base_url }/wp-json/wc-analytics/products/reviews?page=1&per_page=1&status=hold&` + + `_embed=1&_fields%5B0%5D=id&_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-analytics/products/reviews?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); } ); - } ); + } - group( 'Orders Activity', function () { - const requestHeaders = Object.assign( - {}, - jsonAPIRequestHeader, - commonRequestHeaders, - commonAPIGetRequestHeaders, - apiNonceHeader, - commonNonStandardHeaders - ); + if ( includedTests.products ) { + group( 'Products Activity', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); - response = http.get( - `${ base_url }/wp-json/wc-analytics/orders?page=1&per_page=1&status%5B0%5D=processing&` + - `status%5B1%5D=on-hold&_fields%5B0%5D=id&_locale=user`, - { - headers: requestHeaders, - tags: { name: 'Merchant - wc-analytics/orders?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + response = http.get( + `${ base_url }/wp-json/wc-analytics/products/low-in-stock?page=1&per_page=1&` + + `low_in_stock=true&status=publish&_fields%5B0%5D=id&_locale=user`, + { + headers: requestHeaders, + tags: { + name: 'Merchant - wc-analytics/products/low-in-stock?', + }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); } ); - } ); - - group( 'Reviews Activity', function () { - const requestHeaders = Object.assign( - {}, - jsonAPIRequestHeader, - commonRequestHeaders, - commonAPIGetRequestHeaders, - apiNonceHeader, - commonNonStandardHeaders - ); - - response = http.get( - `${ base_url }/wp-json/wc-analytics/products/reviews?page=1&per_page=1&status=hold&` + - `_embed=1&_fields%5B0%5D=id&_locale=user`, - { - headers: requestHeaders, - tags: { name: 'Merchant - wc-analytics/products/reviews?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - } ); - } ); - - group( 'Products Activity', function () { - const requestHeaders = Object.assign( - {}, - jsonAPIRequestHeader, - commonRequestHeaders, - commonAPIGetRequestHeaders, - apiNonceHeader, - commonNonStandardHeaders - ); - - response = http.get( - `${ base_url }/wp-json/wc-analytics/products/low-in-stock?page=1&per_page=1&` + - `low_in_stock=true&status=publish&_fields%5B0%5D=id&_locale=user`, - { - headers: requestHeaders, - tags: { - name: 'Merchant - wc-analytics/products/low-in-stock?', - }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - } ); - } ); + } sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); } diff --git a/plugins/woocommerce/tests/performance/requests/merchant/orders.js b/plugins/woocommerce/tests/performance/requests/merchant/orders.js index 375e831aeba..bf763ce9c6c 100644 --- a/plugins/woocommerce/tests/performance/requests/merchant/orders.js +++ b/plugins/woocommerce/tests/performance/requests/merchant/orders.js @@ -44,11 +44,18 @@ if ( cot_status === true ) { admin_orders_completed = 'post_status=wc-completed'; } -export function orders() { +export function orders( includeTests = {} ) { let response; let api_x_wp_nonce; let apiNonceHeader; let heartbeat_nonce; + let includedTests = Object.assign( { + completed: true, + heartbeat: true, + other: true, + }, + includeTests + ); group( 'All Orders', function () { const requestHeaders = Object.assign( @@ -89,102 +96,108 @@ export function orders() { sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); - group( 'All Orders - Other Requests', function () { - const requestHeaders = Object.assign( - {}, - jsonAPIRequestHeader, - commonRequestHeaders, - commonAPIGetRequestHeaders, - apiNonceHeader, - commonNonStandardHeaders - ); + if ( includedTests.other ) { + group( 'All Orders - Other Requests', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); - response = http.get( - `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, - { - headers: requestHeaders, - tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + response = http.get( + `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, + } + ); + 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, + tags: { name: 'Merchant - wc-analytics/admin/notes?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + + response = http.get( + `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, + { + headers: requestHeaders, + tags: { + name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', + }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + } ); + } + + if ( includedTests.heartbeat ) { + group( 'WP Admin Heartbeat', function () { + const 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_order`, + { + headers: requestHeaders, + tags: { name: 'Merchant - action=heartbeat' }, + } + ); + 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, - tags: { name: 'Merchant - wc-analytics/admin/notes?' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + } + + if ( includedTests.completed ) { + group( 'Completed Orders', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonNonStandardHeaders + ); + + response = http.get( + `${ base_url }/wp-admin/${ admin_orders_base }&${ admin_orders_completed }`, + { + headers: requestHeaders, + tags: { name: 'Merchant - Completed Orders' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Orders' header": ( response ) => + response.body.includes( 'Orders' ), + } ); } ); - response = http.get( - `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, - { - headers: requestHeaders, - tags: { - name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', - }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - } ); - } ); - - group( 'WP Admin Heartbeat', function () { - const 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_order`, - { - headers: requestHeaders, - tags: { name: 'Merchant - action=heartbeat' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - } ); - } ); - - sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); - - group( 'Completed Orders', function () { - const requestHeaders = Object.assign( - {}, - htmlRequestHeader, - commonRequestHeaders, - commonGetRequestHeaders, - commonNonStandardHeaders - ); - - response = http.get( - `${ base_url }/wp-admin/${ admin_orders_base }&${ admin_orders_completed }`, - { - headers: requestHeaders, - tags: { name: 'Merchant - Completed Orders' }, - } - ); - check( response, { - 'is status 200': ( r ) => r.status === 200, - "body contains: 'Orders' header": ( response ) => - response.body.includes( 'Orders' ), - } ); - } ); - - sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + } } export default function () { diff --git a/plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js b/plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js new file mode 100644 index 00000000000..17a937d903b --- /dev/null +++ b/plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js @@ -0,0 +1,303 @@ +/* eslint-disable eqeqeq */ +/* eslint-disable no-undef */ +/** + * Internal dependencies + */ +import { homePage } from '../requests/shopper/home.js'; +import { shopPage } from '../requests/shopper/shop-page.js'; +import { searchProduct } from '../requests/shopper/search-product.js'; +import { singleProduct } from '../requests/shopper/single-product.js'; +import { cart } from '../requests/shopper/cart.js'; +import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js'; +import { cartApplyCoupon } from '../requests/shopper/cart-apply-coupon.js'; +import { checkoutGuest } from '../requests/shopper/checkout-guest.js'; +import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; +import { myAccountOrders } from '../requests/shopper/my-account-orders.js'; +import { categoryPage } from '../requests/shopper/category-page.js'; +import { coupons } from '../requests/merchant/coupons.js'; +import { addProduct } from '../requests/merchant/add-product.js'; +import { orders } from '../requests/merchant/orders.js'; +import { ordersSearch } from '../requests/merchant/orders-search.js'; +import { ordersFilter } from '../requests/merchant/orders-filter.js'; +import { addOrder } from '../requests/merchant/add-order.js'; +import { homeWCAdmin } from '../requests/merchant/home-wc-admin.js'; +import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant.js'; +import { wpLogin } from '../requests/merchant/wp-login.js'; +import { ordersAPI } from '../requests/api/orders.js'; +import { admin_acc_login } from '../config.js'; + +const shopper_request_threshold = 'p(95)<100000'; +const merchant_request_threshold = 'p(95)<100000'; +const api_request_threshold = 'p(95)<100000'; + +export const options = { + scenarios: { + merchantOrders: { + executor: 'ramping-arrival-rate', + startRate: 2, // starting iterations per timeUnit + timeUnit: '10s', + preAllocatedVUs: 5, + maxVUs: 9, + stages: [ + // target value is iterations per timeUnit + { target: 2, duration: '60s' }, + { target: 5, duration: '500s' }, + { target: 1, duration: '60' }, + ], + exec: 'merchantOrderFlows', + }, + merchantOther: { + executor: 'ramping-arrival-rate', + startRate: 2, // starting iterations per timeUnit + timeUnit: '10s', + preAllocatedVUs: 5, + maxVUs: 9, + stages: [ + // target value is iterations per timeUnit + { target: 2, duration: '60s' }, + { target: 5, duration: '500s' }, + { target: 1, duration: '60' }, + ], + exec: 'merchantOtherFlows', + }, + shopperBrowsing: { + executor: 'ramping-arrival-rate', + startRate: 2, // starting iterations per timeUnit + timeUnit: '10s', + preAllocatedVUs: 5, + maxVUs: 9, + stages: [ + // target value is iterations per timeUnit + { target: 2, duration: '60s' }, + { target: 10, duration: '500s' }, + { target: 1, duration: '60' }, + ], + exec: 'shopperBrowsingFlows', + }, + shopperGuestCheckouts: { + executor: 'ramping-arrival-rate', + startRate: 2, // starting iterations per timeUnit + timeUnit: '10s', + preAllocatedVUs: 5, + maxVUs: 9, + stages: [ + // target value is iterations per timeUnit + { target: 2, duration: '60s' }, + { target: 5, duration: '500s' }, + { target: 1, duration: '60' }, + ], + exec: 'checkoutGuestFlow', + }, + shopperCustomerCheckouts: { + executor: 'ramping-arrival-rate', + startRate: 2, // starting iterations per timeUnit + timeUnit: '10s', + preAllocatedVUs: 5, + maxVUs: 9, + stages: [ + // target value is iterations per timeUnit + { target: 2, duration: '60s' }, + { target: 5, duration: '500s' }, + { target: 1, duration: '60' }, + ], + exec: 'checkoutCustomerLoginFlow', + }, + apiBackground: { + executor: 'ramping-arrival-rate', + startRate: 1, // starting iterations per timeUnit + timeUnit: '10s', + preAllocatedVUs: 5, + maxVUs: 5, + stages: [ + // target value is iterations per timeUnit + { target: 1, duration: '60s' }, + { target: 5, duration: '500s' }, + { target: 1, duration: '60' }, + ], + exec: 'allAPIFlow', + }, + }, + thresholds: { + // Listing individual metrics due to https://github.com/grafana/k6/issues/1321 + 'http_req_duration{name:Shopper - Site Root}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Shop Page}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Search Products}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Category Page}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Product Page}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - wc-ajax=add_to_cart}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - View Cart}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Remove Item From Cart}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - wc-ajax=apply_coupon}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Update Cart}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - View Checkout}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - wc-ajax=update_order_review}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - wc-ajax=checkout}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Order Received}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - wc-ajax=get_refreshed_fragments}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Login to Checkout}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - My Account Login Page}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - Login to My Account}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - My Account}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - My Account Orders}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Shopper - My Account Open Order}': [ + `${ shopper_request_threshold }`, + ], + 'http_req_duration{name:Merchant - WP Login Page}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Login to WP Admin}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - WC-Admin}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - wc-analytics/orders?}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - All Orders}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Completed Orders}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - New Order Page}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Create New Order}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Open Order}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Update Existing Order Status}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Search Orders By Product}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Search Orders By Customer Email}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Search Orders By Customer Address}': + [ `${ merchant_request_threshold }` ], + 'http_req_duration{name:Merchant - Filter Orders By Month}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Filter Orders By Customer}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - All Products}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Add New Product}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:Merchant - Update New Product}': [ + `${ merchant_request_threshold }`, + ], + 'http_req_duration{name:API - Create Order}': [ + `${ api_request_threshold }`, + ], + 'http_req_duration{name:API - Retrieve Order}': [ + `${ api_request_threshold }`, + ], + 'http_req_duration{name:API - Update Order (Status)}': [ + `${ api_request_threshold }`, + ], + 'http_req_duration{name:API - Delete Order}': [ + `${ api_request_threshold }`, + ], + 'http_req_duration{name:API - Batch Create Orders}': [ + `${ api_request_threshold }`, + ], + 'http_req_duration{name:API - Batch Update (Status) Orders}': [ + `${ api_request_threshold }`, + ], + }, +}; + +// Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. +export function merchantOrderFlows() { + if ( admin_acc_login === true ) { + myAccountMerchantLogin(); + } else { + wpLogin(); + } + addOrder( { heartbeat: false, other: false } ); + orders( { heartbeat: false, other: false } ); + ordersSearch(); + ordersFilter(); +} + +// Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. +export function merchantOtherFlows() { + if ( admin_acc_login === true ) { + myAccountMerchantLogin(); + } else { + wpLogin(); + } + homeWCAdmin( { other: false, products: false, reviews: false } ); + addProduct( { heartbeat: false, other: false, permalink: false, update: false } ); + coupons(); +} +export function shopperBrowsingFlows() { + homePage(); + shopPage(); + searchProduct(); + singleProduct(); + cartRemoveItem(); + cartApplyCoupon(); + categoryPage(); +} +export function checkoutGuestFlow() { + cart(); + checkoutGuest(); +} +export function checkoutCustomerLoginFlow() { + cart(); + checkoutCustomerLogin(); + myAccountOrders(); +} +export function allAPIFlow() { + ordersAPI(); +}