Merge pull request #31921 from woocommerce/try/k6-run-ci-onpr

Run k6 tests on PR after e2e and API
This commit is contained in:
Ron Rennick 2022-02-18 10:55:31 -04:00 committed by GitHub
commit 101347788f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 205 additions and 5 deletions

View File

@ -134,3 +134,67 @@ jobs:
USER_KEY: admin USER_KEY: admin
USER_SECRET: password USER_SECRET: password
run: pnpx wc-api-tests test api run: pnpx wc-api-tests test api
k6-tests-run:
name: Runs k6 Performance tests
runs-on: ubuntu-18.04
needs: [build]
steps:
- name: Create dirs.
run: |
mkdir -p code/woocommerce
mkdir -p package/woocommerce
mkdir -p tmp/woocommerce
mkdir -p node_modules
- name: Checkout code.
uses: actions/checkout@v2
with:
path: package/woocommerce
- name: Install PNPM and install dependencies
working-directory: package/woocommerce
run: |
npm install -g pnpm
pnpm install
- name: Workaround to use initialization file with prepopulated data.
working-directory: package/woocommerce/plugins/woocommerce/tests/e2e/docker
run: |
cp init-sample-products.sh initialize.sh
- name: Load docker images and start containers.
working-directory: package/woocommerce/plugins/woocommerce
run: pnpx wc-e2e docker:up
- name: Move current directory to code. We will install zip file in this dir later.
run: mv ./package/woocommerce/plugins/woocommerce/* ./code/woocommerce
- name: Download WooCommerce ZIP.
uses: actions/download-artifact@v2
with:
name: woocommerce
path: tmp
- name: Extract and replace WooCommerce zip.
working-directory: tmp
run: |
unzip woocommerce.zip -d woocommerce
mv woocommerce/woocommerce/* ../package/woocommerce/plugins/woocommerce/
- name: Install dependencies again
working-directory: package/woocommerce
run: |
npm install -g pnpm
pnpm install
- name: Wait for the Docker container to be built
working-directory: package/woocommerce/plugins/woocommerce
run: pnpx wc-e2e docker:wait
- name: Install k6
run: |
curl https://github.com/grafana/k6/releases/download/v0.33.0/k6-v0.33.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
- name: Run k6 tests
run: |
./k6 run package/woocommerce/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js

View File

@ -15,6 +15,7 @@
- `WC_E2E_FOLDER` for mapping plugin root to path within repo - `WC_E2E_FOLDER` for mapping plugin root to path within repo
- Added the `resolveSingleE2EPath()` method which builds a path to a specific E2E test - Added the `resolveSingleE2EPath()` method which builds a path to a specific E2E test
- Added the ability to take screenshots from multiple test failures (when retried) in `utils/take-screenshot.js`. - Added the ability to take screenshots from multiple test failures (when retried) in `utils/take-screenshot.js`.
- `docker:wait` to allow for waiting for env to be built without running tests
## Changed ## Changed

View File

@ -9,6 +9,7 @@ usage() {
echo 'scripts:' echo 'scripts:'
echo ' docker:up [initialization-script] - boot docker container' echo ' docker:up [initialization-script] - boot docker container'
echo ' docker:down - shut down docker container' echo ' docker:down - shut down docker container'
echo ' docker:wait - wait for env to be built'
echo ' docker:ssh - open SSH shell into docker container' echo ' docker:ssh - open SSH shell into docker container'
echo ' docker:clear-all - remove all docker containers' echo ' docker:clear-all - remove all docker containers'
echo ' test:e2e [test-script] - run e2e test suite or specific test-script' echo ' test:e2e [test-script] - run e2e test suite or specific test-script'
@ -50,6 +51,9 @@ case $1 in
'docker:up') 'docker:up')
./bin/docker-compose.sh up $2 ./bin/docker-compose.sh up $2
;; ;;
'docker:wait')
./bin/wait-for-build.sh
;;
'docker:down') 'docker:down')
./bin/docker-compose.sh down ./bin/docker-compose.sh down
;; ;;

View File

@ -66,6 +66,7 @@
"build": "pnpm run clean && pnpm run compile", "build": "pnpm run clean && pnpm run compile",
"prepare": "pnpm run build", "prepare": "pnpm run build",
"docker:up": "./bin/docker-compose.sh up", "docker:up": "./bin/docker-compose.sh up",
"docker:wait": "bash ./bin/wait-for-build.sh",
"docker:down": "./bin/docker-compose.sh down", "docker:down": "./bin/docker-compose.sh down",
"docker:clear-all": "docker rmi --force $(docker images -q)", "docker:clear-all": "docker rmi --force $(docker images -q)",
"docker:ssh": "docker exec -it $(node utils/get-app-name.js)_wordpress-www /bin/bash", "docker:ssh": "docker exec -it $(node utils/get-app-name.js)_wordpress-www /bin/bash",

View File

@ -55,8 +55,8 @@ export function orders() {
); );
api_x_wp_nonce = findBetween( api_x_wp_nonce = findBetween(
response.body, response.body,
'wp-json\\/","nonce":"', 'wp.apiFetch.createNonceMiddleware( "',
'",' '" )'
); );
// Create request header with nonce value for use in subsequent requests. // Create request header with nonce value for use in subsequent requests.

View File

@ -5,7 +5,7 @@ import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
import { import {
base_url, base_url,
product_url, product_url,
product_id, product_sku,
think_time_min, think_time_min,
think_time_max, think_time_max,
} from "../../config.js"; } from "../../config.js";
@ -36,8 +36,8 @@ export function singleProduct() {
productPageTrend.add(response.timings.duration); productPageTrend.add(response.timings.duration);
check(response, { check(response, {
"is status 200": (r) => r.status === 200, "is status 200": (r) => r.status === 200,
"body contains: product ID": (response) => "body contains: product SKU": (response) =>
response.body.includes(`id="product-${product_id}`), response.body.includes(`class="sku">${product_sku}`),
}); });
}); });

View File

@ -0,0 +1,130 @@
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 { checkoutGuest } from '../requests/shopper/checkout-guest.js';
import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js';
import { myAccount } from '../requests/shopper/my-account.js';
import { categoryPage } from '../requests/shopper/category-page.js';
import { wpLogin } from '../requests/merchant/wp-login.js';
import { products } from '../requests/merchant/products.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 { homeWCAdmin } from '../requests/merchant/home-wc-admin.js';
export let options = {
scenarios: {
homePageSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '60s',
exec: 'homePageFlow',
},
shopPageSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '60s',
startTime: '5s',
exec: 'shopPageFlow',
},
searchProductSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '60s',
startTime: '10s',
exec: 'searchProductFlow',
},
singleProductSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '60s',
startTime: '15s',
exec: 'singleProductFlow',
},
myAccountSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '60s',
startTime: '20s',
exec: 'myAccountFlow',
},
cartSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '60s',
startTime: '25s',
exec: 'cartFlow',
},
checkoutGuestSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '120s',
startTime: '30s',
exec: 'checkoutGuestFlow',
},
checkoutCustomerLoginSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '120s',
startTime: '40s',
exec: 'checkoutCustomerLoginFlow',
},
allMerchantSmoke: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 3,
maxDuration: '360s',
exec: 'allMerchantFlow',
},
},
thresholds: {
checks: [ 'rate==1' ],
},
};
export function homePageFlow() {
homePage();
}
export function shopPageFlow() {
shopPage();
}
export function searchProductFlow() {
searchProduct();
}
export function singleProductFlow() {
singleProduct();
categoryPage();
}
export function checkoutGuestFlow() {
cart();
checkoutGuest();
}
export function checkoutCustomerLoginFlow() {
cart();
checkoutCustomerLogin();
}
export function myAccountFlow() {
myAccount();
}
export function cartFlow() {
cartRemoveItem();
}
export function allMerchantFlow() {
wpLogin();
homeWCAdmin();
orders();
ordersSearch();
products();
addProduct();
}