diff --git a/.github/workflows/cot-pr-build-and-e2e-tests.yml b/.github/workflows/non-cot-pr-build-and-e2e-tests.yml similarity index 87% rename from .github/workflows/cot-pr-build-and-e2e-tests.yml rename to .github/workflows/non-cot-pr-build-and-e2e-tests.yml index 02cfb498434..f54fc1dce89 100644 --- a/.github/workflows/cot-pr-build-and-e2e-tests.yml +++ b/.github/workflows/non-cot-pr-build-and-e2e-tests.yml @@ -1,4 +1,4 @@ -name: Run tests against PR in an environment with COT enabled +name: Run tests against PR in an environment with HPOS disabled on: pull_request: workflow_dispatch: @@ -10,8 +10,8 @@ concurrency: permissions: {} jobs: - cot-e2e-tests-run: - name: Runs E2E tests with COT enabled. + non-hpos-e2e-tests-run: + name: Runs E2E tests with HPOS disabled. runs-on: ubuntu-20.04 permissions: contents: read @@ -24,11 +24,9 @@ jobs: - name: Setup WooCommerce Monorepo uses: ./.github/actions/setup-woocommerce-monorepo - - name: Load docker images and start containers with COT enabled. + - name: Load docker images and start containers working-directory: plugins/woocommerce - env: - ENABLE_HPOS: 1 - run: pnpm env:test:cot --filter=woocommerce + run: pnpm env:test --filter=woocommerce - name: Download and install Chromium browser. working-directory: plugins/woocommerce @@ -39,6 +37,7 @@ jobs: id: run_playwright_e2e_tests env: USE_WP_ENV: 1 + ENABLE_HPOS: 0 working-directory: plugins/woocommerce run: pnpm exec playwright test --config=tests/e2e-pw/playwright.config.js @@ -66,8 +65,8 @@ jobs: if-no-files-found: ignore retention-days: 5 - cot-api-tests-run: - name: Runs API tests with COT enabled. + non-hpos-api-tests-run: + name: Runs API tests with HPOS disabled. runs-on: ubuntu-20.04 permissions: contents: read @@ -80,11 +79,9 @@ jobs: - name: Setup WooCommerce Monorepo uses: ./.github/actions/setup-woocommerce-monorepo - - name: Load docker images and start containers with COT enabled. + - name: Load docker images and start containers working-directory: plugins/woocommerce - env: - ENABLE_HPOS: 1 - run: pnpm env:test:cot --filter=woocommerce + run: pnpm env:test --filter=woocommerce - name: Run Playwright API tests. id: run_playwright_api_tests @@ -93,6 +90,7 @@ jobs: BASE_URL: http://localhost:8086 USER_KEY: admin USER_SECRET: password + ENABLE_HPOS: 0 run: pnpm exec playwright test --config=tests/api-core-tests/playwright.config.js - name: Generate Playwright API Test report. @@ -117,4 +115,4 @@ jobs: ${{ env.ALLURE_RESULTS_DIR }} ${{ env.ALLURE_REPORT_DIR }} if-no-files-found: ignore - retention-days: 5 + retention-days: 5 \ No newline at end of file diff --git a/.github/workflows/pr-build-and-e2e-tests.yml b/.github/workflows/pr-build-and-e2e-tests.yml index bcb64f055a0..0a2b8d2ae60 100644 --- a/.github/workflows/pr-build-and-e2e-tests.yml +++ b/.github/workflows/pr-build-and-e2e-tests.yml @@ -31,7 +31,6 @@ jobs: - name: Load docker images and start containers. working-directory: plugins/woocommerce env: - ENABLE_HPOS: 0 WP_ENV_PHP_VERSION: 7.4 run: pnpm run env:test @@ -265,4 +264,4 @@ jobs: -f pr_number=$PR_NUMBER \ -f commit_sha=$COMMIT_SHA \ -f s3_root=public \ - --repo woocommerce/woocommerce-test-reports + --repo woocommerce/woocommerce-test-reports \ No newline at end of file diff --git a/plugins/woocommerce/changelog/e2e-ensure-HPOS-is-disabled-when-required b/plugins/woocommerce/changelog/e2e-ensure-HPOS-is-disabled-when-required new file mode 100644 index 00000000000..d1e949dc35c --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-ensure-HPOS-is-disabled-when-required @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Ensure HPOS is disabled when ENABLE_HPOS is undefined or set to '0' diff --git a/plugins/woocommerce/tests/api-core-tests/global-setup.js b/plugins/woocommerce/tests/api-core-tests/global-setup.js index 9997f5cedca..09dcddbc598 100644 --- a/plugins/woocommerce/tests/api-core-tests/global-setup.js +++ b/plugins/woocommerce/tests/api-core-tests/global-setup.js @@ -1,8 +1,10 @@ -const { GITHUB_TOKEN, UPDATE_WC } = process.env; +const { ENABLE_HPOS, GITHUB_TOKEN, UPDATE_WC } = process.env; const { downloadZip, deleteZip } = require( './utils/plugin-utils' ); const axios = require( 'axios' ).default; +const playwrightConfig = require('./playwright.config'); module.exports = async ( config ) => { + // If API_BASE_URL is configured and doesn't include localhost, running on daily host if ( process.env.API_BASE_URL && @@ -197,5 +199,29 @@ module.exports = async ( config ) => { } else { console.log( 'No DB update needed' ); } + } else { + // running on localhost using wp-env so ensure HPOS is set if ENABLE_HPOS env variable is passed + if (ENABLE_HPOS) { + let hposConfigured = false; + const value = ENABLE_HPOS === '0' ? 'no' : 'yes'; + try { + const auth = { username: playwrightConfig.userKey, password: playwrightConfig.userSecret }; + const hposResponse = await axios.post( playwrightConfig.use.baseURL + '/wp-json/wc/v3/settings/advanced/woocommerce_custom_orders_table_enabled', { value }, { auth } ); + if ( hposResponse.data.value === value ) { + console.log( `HPOS Switched ${ value === 'yes' ? 'on' : 'off' } successfully` ); + hposConfigured = true; + } + } catch( error ) { + console.log( 'HPOS setup failed.'); + console.log( error ); + process.exit( 1 ); + } + if ( ! hposConfigured ) { + console.error( + 'Cannot proceed to api tests, HPOS configuration failed. Please check if the correct ENABLE_HPOS value was used and the test site has been setup correctly.' + ); + process.exit( 1 ); + } + } } }; diff --git a/plugins/woocommerce/tests/api-core-tests/playwright.config.js b/plugins/woocommerce/tests/api-core-tests/playwright.config.js index 281dc7711a6..6a3c9207974 100644 --- a/plugins/woocommerce/tests/api-core-tests/playwright.config.js +++ b/plugins/woocommerce/tests/api-core-tests/playwright.config.js @@ -10,6 +10,8 @@ const userSecret = USER_SECRET ?? 'password'; const base64auth = btoa( `${ userKey }:${ userSecret }` ); const config = { + userKey, + userSecret, timeout: DEFAULT_TIMEOUT_OVERRIDE ? Number( DEFAULT_TIMEOUT_OVERRIDE ) : 90 * 1000, diff --git a/plugins/woocommerce/tests/e2e-pw/bin/test-env-setup.sh b/plugins/woocommerce/tests/e2e-pw/bin/test-env-setup.sh index 80596f89bfa..14b844261b1 100755 --- a/plugins/woocommerce/tests/e2e-pw/bin/test-env-setup.sh +++ b/plugins/woocommerce/tests/e2e-pw/bin/test-env-setup.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -ENABLE_HPOS="${ENABLE_HPOS:-0}" ENABLE_TRACKING="${ENABLE_TRACKING:-0}" echo -e 'Activate twentynineteen theme \n' @@ -29,12 +28,6 @@ wp-env run tests-cli wp option update blogname 'WooCommerce Core E2E Test Suite' echo -e 'Preparing Test Files \n' wp-env run tests-cli sudo cp /var/www/html/wp-content/plugins/woocommerce/tests/legacy/unit-tests/importer/sample.csv /var/www/sample.csv -if [ $ENABLE_HPOS == 1 ]; then - echo -e 'Enable High-Performance Order Tables\n' - wp-env run tests-cli wp option update woocommerce_feature_custom_order_tables_enabled 'yes' - wp-env run tests-cli wp option update woocommerce_custom_orders_table_enabled 'yes' -fi - if [ $ENABLE_TRACKING == 1 ]; then echo -e 'Enable tracking\n' wp-env run tests-cli wp option update woocommerce_allow_tracking 'yes' diff --git a/plugins/woocommerce/tests/e2e-pw/global-setup.js b/plugins/woocommerce/tests/e2e-pw/global-setup.js index 4583ee455fb..c46ded52ac8 100644 --- a/plugins/woocommerce/tests/e2e-pw/global-setup.js +++ b/plugins/woocommerce/tests/e2e-pw/global-setup.js @@ -2,6 +2,8 @@ const { chromium, expect } = require( '@playwright/test' ); const { admin, customer } = require( './test-data/data' ); const fs = require( 'fs' ); const { site } = require( './utils' ); +const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; +const { ENABLE_HPOS } = process.env; module.exports = async ( config ) => { const { stateDir, baseURL, userAgent } = config.projects[ 0 ].use; @@ -39,6 +41,7 @@ module.exports = async ( config ) => { let adminLoggedIn = false; let customerLoggedIn = false; let customerKeyConfigured = false; + let hposConfigured = false; // Specify user agent when running against an external test site to avoid getting HTTP 406 NOT ACCEPTABLE errors. const contextOptions = { baseURL, userAgent }; @@ -178,6 +181,44 @@ module.exports = async ( config ) => { process.exit( 1 ); } + // While we're here, let's set HPOS according to the passed in ENABLE_HPOS env variable + // (if a value for ENABLE_HPOS was set) + // This was always being set to 'yes' after login in wp-env so this step ensures the + // correct value is set before we begin our tests + if (ENABLE_HPOS) { + const hposSettingRetries = 5; + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + + const value = ENABLE_HPOS === '0' ? 'no' : 'yes'; + + for (let i = 0; i < hposSettingRetries; i++) { + try { + console.log( `Trying to switch ${ value === 'yes' ? 'on' : 'off' } HPOS...` ); + const response = await api.post( 'settings/advanced/woocommerce_custom_orders_table_enabled', { value } ); + if ( response.data.value === value ) { + console.log( `HPOS Switched ${ value === 'yes' ? 'on' : 'off' } successfully` ); + hposConfigured = true; + break; + } + } catch (e) { + console.log( `HPOS setup failed. Retrying... ${ i }/${ hposSettingRetries }` ); + console.log(e); + } + } + + if ( ! hposConfigured ) { + console.error( + 'Cannot proceed e2e test, HPOS configuration failed. Please check if the correct ENABLE_HPOS value was used and the test site has been setup correctly.' + ); + process.exit( 1 ); + } + } + await adminContext.close(); await customerContext.close(); await browser.close();