Skip to content

Commit

Permalink
fix integration tests (#712)
Browse files Browse the repository at this point in the history
* install and setup node and pnpm on self hosted runner
* install pnpm first
* configure package.json and lock file locations
* run pnpm install before trying to setup playwright
* install playwright dependencies
* run dotnet tests when playwright fails
* Only upload Playwright traces if password-protected
* Try standalone pnpm setup
* Fix condition syntax
* Set up Node twice
* Only password-protect Playwright results if they exist
* Try setting Playwright timeout to 2 minutes
* Reduce number of unneeded Playwright traces

We don't need traces of successful tests, so let's try to reduce the
size of the Playwright trace file we'll be uploading after the run.

* Try different syntax for Playwright trace step

GHA workflow example shows `if: ${{ always() }}` so let's try moving it
inside the braces.

* Fix one failing test

The "page load 403 is redirected to home" test was pretty much always
failing because we were failing to await the page load event correctly.

* Try using no compression in 7z step

Maybe using no compression will let 7z complete its step without running
out of RAM.

* Fix 7z CLI format, also do not use threading
* Add TODO note re caching
* Note another useful cache location
* Fix if: syntax for rest of test
* Always set up pnpm, not just on self-hosted

The GHA ubuntu-latest runner doesn't have pnpm either.

* Fix integration test name

vars.TEST_SERVER_HOSTNAME is not available to the runner at the time the
test run name is being set up, so replace it with inputs.environment.

* GHA ubuntu-latest runner can't run sudo pnpm
* Double total timeout minutes for test job

Since some runs are passing 1 hour, we want to let them complete.

* Reduce Playwright timeout to 1 minute

This should give enough time for Playwright tests to complete even under
load; experimental testing with a 2-minute timeout showed tests either
finishing under 60s, or running all the way to the 2-minute timeout.

* Fix syntax for step outcome
* Upload Playwright traces even if prior steps fail
* install wget as needed by ubuntu 22 image
* change develop integration tests to use hg 6 instead of 3 to simplify dependencies
* set run name the same as the job name
* Keep all Playwright traces again
* Set Playwright timeout back to default

---------

Co-authored-by: Robin Munn <rmunn@pobox.com>
  • Loading branch information
hahn-kev and rmunn authored Apr 11, 2024
1 parent 24ecb3d commit 4f92d9c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/develop-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ jobs:
with:
environment: develop
runs-on: self-hosted
hg-version: 6
43 changes: 34 additions & 9 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Integration Tests
run-name: Test ${{ inputs.runs-on }} for Mercurial ${{ inputs.hg-version }} on ${{ inputs.environment }}
on:
workflow_call:
inputs:
Expand Down Expand Up @@ -43,8 +44,8 @@ on:

jobs:
test:
timeout-minutes: 60
name: Test ${{ inputs.runs-on }} for Mercurial ${{ inputs.hg-version }} on ${{ vars.TEST_SERVER_HOSTNAME }}
timeout-minutes: 120
name: Test ${{ inputs.runs-on }} for Mercurial ${{ inputs.hg-version }} on ${{ inputs.environment }}
permissions:
checks: write
environment:
Expand All @@ -55,13 +56,27 @@ jobs:
- name: Setup self-hosted dependencies
if: ${{ inputs.runs-on == 'self-hosted' }}
run: |
sudo apt-get update
sudo apt-get install -y p7zip-full wget zlib1g-dev libssl-dev #needed by setup python
wget -q https://github.com/PowerShell/PowerShell/releases/download/v7.4.1/powershell_7.4.1-1.deb_amd64.deb
sudo dpkg -i powershell_7.4.1-1.deb_amd64.deb
sudo apt-get install -f
rm powershell_7.4.1-1.deb_amd64.deb
sudo apt-get update
sudo apt-get install -y p7zip-full zlib1g-dev libssl-dev #needed by setup python
pwsh #validate that powershell installed correctly
# First we need to setup Node...
- uses: actions/setup-node@v4
with:
node-version-file: 'frontend/package.json'
# Then we can set up pnpm...
- uses: pnpm/action-setup@v3
with:
package_json_file: 'frontend/package.json'
# Then we can have Noede set up package caching
- uses: actions/setup-node@v4
with:
node-version-file: 'frontend/package.json'
cache: 'pnpm'
cache-dependency-path: 'frontend/pnpm-lock.yaml'
- uses: actions/setup-dotnet@v3
env:
DOTNET_INSTALL_DIR: ${{ inputs.runs-on == 'self-hosted' && '/opt/hostedtoolcache/dotnet' || '' }} #poor man's conditional
Expand All @@ -80,16 +95,25 @@ jobs:
sudo ln -s ${{ steps.python.outputs.python-path }} /usr/bin/python2
- name: Dotnet build
run: dotnet build
# TODO: Set up caching for /home/runner/.cache/ms-playwright so this doesn't take as long
# TODO: Ditto for /home/runner/.pnpm-store/v3
# TODO: Ditto for /home/runner/.nuget/packages
# TODO: Ditto for /var/cache/apt/archives/
- name: Playwright setup
working-directory: frontend
if: ${{ inputs.run-playwright }}
run: pnpm pretest
run: pnpm install && pnpm pretest
- name: Set up Playwright dependencies
working-directory: frontend
if: ${{ inputs.run-playwright && inputs.runs-on == 'self-hosted' }}
run: sudo pnpm exec playwright install-deps
- name: Build for tests
run: "dotnet build /p:MercurialVersion=$MERCURIAL_VERSION"
env:
MERCURIAL_VERSION: ${{ inputs.hg-version }}
- name: Integration tests (Playwright)
if: ${{ inputs.run-playwright }}
continue-on-error: true
env:
TEST_SERVER_HOSTNAME: ${{ vars.TEST_SERVER_HOSTNAME }}
# this is not a typo, we need to use the lf domain because it has a cert that hg will validate
Expand All @@ -109,19 +133,20 @@ jobs:
TEST_DEFAULT_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
run: dotnet test --output ./bin --logger trx --results-directory ./test-results --filter Category=Integration
- name: Password protect Playwright traces
if: always()
id: password_protect_test_results
if: ${{ always() && inputs.run-playwright }}
shell: bash
env:
ZIP_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
run: 7z a ./playwright-traces.7z ./frontend/test-results -p"$ZIP_PASSWORD"
run: 7z a ./playwright-traces.7z -mx=0 -mmt=off ./frontend/test-results -p"$ZIP_PASSWORD"
- name: Publish unit test results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
if: always() && !env.act
if: ${{ always() && !env.act }}
with:
check_name: Integration Tests ${{ inputs.runs-on }} for Mercurial ${{ inputs.hg-version }}
files: ./test-results/*.trx
- name: Upload playwright results
if: always()
if: ${{ always() && steps.password_protect_test_results.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: playwright-traces-${{ inputs.runs-on }}-hg-${{ inputs.hg-version }}
Expand Down
4 changes: 3 additions & 1 deletion frontend/tests/errorHandling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ test('can catch 403 errors from goto in new tab', async ({ page, context }) => {
test('page load 403 is redirected to home', async ({ page }) => {
await loginAs(page.request, 'manager', testEnv.defaultPassword);
await new SandboxPage(page).goto();
const pagePromise = page.context().waitForEvent('page');
await page.getByText('Goto page load 403', {exact: true}).click();
await new UserDashboardPage(page).waitFor();
const newPage = await pagePromise;
await new UserDashboardPage(newPage).waitFor();
});

test('page load 403 in new tab is redirected to home', async ({ page }) => {
Expand Down

0 comments on commit 4f92d9c

Please sign in to comment.