-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sharding to e2e tests #89
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some initial comments
I'm testing this out here: HHS/simpler-grants-gov#2599 It seems to work but unclear if it actually speeds things up. Still working on that PR. |
Would be great if there is a way to cache the steps before the matrix. It looks like the all of the build steps are repeated for each one, which is where most of the time for us is spent. |
@acouch on the other e2e Dockerize PR we optimized it a little bit to create the install as one layer so it would cache better #88 (comment) . (we are close to merging there so may want to take a peek at it for grants) However I don't know if that caching will translate to multiple shard runs, I think each shard run will need to do the full build each time - will have to research that. It may be that sharding is only beneficial when the bottleneck is the test run time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good just had a few questions
.github/workflows/e2e-tests.yml
Outdated
ls -R ./e2e/blob-report || echo "blob-report directory not found" | ||
|
||
- name: Upload Blob Report | ||
if: ${{ !cancelled() }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: what use case is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An extra safeguard that on manual or timeout-based cancellations, steps within create-report
don't run - but I think since create-report
has a needs
dependency on e2e
we don't need ths line - let's remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were originally using it in there merge and upload blob reports on the playwright sharding docs https://playwright.dev/docs/test-sharding#github-actions-example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you look at their example it's because they set fail-fast to false, but they still want to upload the blob even if the e2e tests failed, and they still want to merge even if some of the shards failed. seems like we'd want to do the same, and add a comment saying that "still upload report even if previous step failed"
.github/workflows/e2e-tests.yml
Outdated
- name: Install dependencies in ./e2e | ||
run: make e2e-setup-ci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, how come we're running e2e tests in Docker but running the merge reports natively?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The create-report
job has to be in a separate "job" that runs after all the shard runs - merging can't really be done in any one of the shard job containers.
I'm not sure there's any need to increase our CI job run time to spin up a container to do a merge. And merging reports probably only needs to run in CI.
Locally I don't think we'd ever want to shard - so the report there is just html in the playwright-report
folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also raises the question - should the e2e
job (running of tests) instead be run natively in CI? It may speed things up if we just run tests natively vs a container.
However, I think we should still use docker in CI - the CI run should be consistent to how you run it locally in the container. E2E tests can be flaky and I think it makes sense to eliminate any environment issues at play both locally and in the CI run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense thanks for explaining. I still think it'd be valuable to convert the line run: npx playwright merge-reports --reporter html ./all-blob-reports
to a make target like run: make e2e-merge-report
or something like that so that we can test the sharding locally. I think also that in order to test sharding locally, when we download the blob artifacts we should download them to the same place that they were in originally.
so in other words locally we can do
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=1
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=2
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=3
make e2e-merge-reports
and in CI we'd do something like
jobs:
e2e:
matrix:
shard: [1,2,3]
total_shards: [3]
steps:
- run: make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=${ matrix.total_shards } CURRENT_SHARD=${ matrix.shard }
- # upload artifact from ./e2e/blob-report/*
create-report:
steps:
- # download artifact to ./e2e/blob-report/
- run: make e2e-merge-reports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lorenyu you also have to set CI=true
right now - but this does work locally - we can try in followup pr:
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=1 CI=true
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=2 CI=true
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=3 CI=true
cd e2e
npx playwright merge-reports --reporter html ./blob-report
cd ..
make e2e-show-report
make e2e-clean-report
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened the PR on template infra to merge part 1 and will try to clean some of this up in part 2 pr
e2e-test: e2e-build | ||
@:$(call check_defined, APP_NAME, You must pass in a specific APP_NAME) | ||
@:$(call check_defined, BASE_URL, You must pass in a BASE_URL) | ||
docker run --rm \ | ||
docker run --rm\ | ||
--name playwright-e2e-container \ | ||
-e APP_NAME=$(APP_NAME) \ | ||
-e BASE_URL=$(BASE_URL) \ | ||
-e CURRENT_SHARD=$(CURRENT_SHARD) \ | ||
-e TOTAL_SHARDS=$(TOTAL_SHARDS) \ | ||
-e CI=$(CI) \ | ||
-v $(PWD)/e2e/playwright-report:/e2e/playwright-report \ | ||
-v $(PWD)/e2e/blob-report:/e2e/blob-report \ | ||
playwright-e2e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: What happens if you run make e2e-test
with CURRENT_SHARD and TOTAL_SHARDS undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run it locally with those values undefined - it just defaults to 1 per ./e2e/playwright.config.js
:
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001
local output:
Running 6 tests using 6 workers, shard 1 of 1
make e2e-test
runs the container - which invokes the default Dockerfile CMD
of make e2e-test-native
- which invokes npx playwright test
- which runs test with the config ./e2e/playwright.config.js
- which defaults the shards to 1
platform-test-nextjs/e2e/playwright.config.js
Lines 36 to 41 in 1a1e63c
shard: { | |
// Total number of shards | |
total: parseInt(process.env.TOTAL_SHARDS || '1'), | |
// Specifies which shard this job should execute | |
current: parseInt(process.env.CURRENT_SHARD || '1'), | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm if I run with TOTAL_SHARDS
set locally it actually just runs 1 shard - I'm not sure if we want to support sharding locally
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3
....
Running 2 tests using 2 workers, shard 1 of 3
(just runs 2 of the 6 total tests)
I don't think we need to support sharding in local
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to support sharding in local
That's fine, but for testing purposes you can still run the following right?
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=1
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=2
make e2e-test APP_NAME=app BASE_URL=http://host.docker.internal:3001 TOTAL_SHARDS=3 CURRENT_SHARD=3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but for testing purposes you can still run the following right?
see the comment above #89 (comment)
Co-authored-by: Loren Yu <[email protected]>
…-test-nextjs into rylew/e2e-shard
I propose a fast follow PR for docs updates and trying to better cache some of the docker - right now it takes about 7-8 minutes to run |
Sounds good to me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, feel free to do the change I requested in a followup PR. For reference the change I requested is to:
- change the download artifact path from ./all-blob-reports to ./e2e/blob-report
- move the line
npx playwright merge-reports --reporter html ./e2e/blob-report
into a make target likemake e2e-merge-reports
this way we can test locally and also run in CI
npx playwright merge-reports --reporter html ./all-blob-reports
Co-authored-by: Loren Yu <[email protected]>
Ticket
Resolves navapbc/template-infra#720
Changes
https://playwright.dev/docs/test-sharding
TODO
Will likely be part 1 of 2 PR - additional items in future PR:
Demo
CI:
382633894-ae91a0bd-c3d7-4920-9432-2897df1d064b.2.mov
Local:
output.mov
Preview environment
♻️ Environment destroyed ♻️