Skip to content

Commit 4345d0d

Browse files
[test optimization] Cache oldest versions of playwright and improve retries (#7017)
1 parent 7a4b1c3 commit 4345d0d

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

.github/workflows/test-optimization.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ jobs:
7070
with:
7171
version: ${{ matrix.node-version }}
7272
- uses: ./.github/actions/install
73+
# We need this because the "oldest" playwright version depends on the major version of dd-trace
74+
# For v5 it's 1.18.0 and for v6 it's 1.38.0
75+
# We don't cache "latest" because it changes based on playwright releases.
76+
# We could do it, but we'd have to request GitHub API to get the latest version,
77+
# and the cache hit rate would be way lower than for "oldest", which should be 100%.
78+
- name: Get dd-trace major version
79+
if: matrix.playwright-version == 'oldest'
80+
id: dd-version
81+
run: |
82+
VERSION=$(node -p "require('./package.json').version")
83+
MAJOR=$(echo $VERSION | cut -d. -f1)
84+
echo "major=$MAJOR" >> $GITHUB_OUTPUT
85+
echo "dd-trace major version: $MAJOR"
86+
- name: Cache Playwright browsers
87+
if: matrix.playwright-version == 'oldest'
88+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
89+
with:
90+
path: /github/home/.cache/ms-playwright
91+
key: playwright-browsers-oldest-dd${{ steps.dd-version.outputs.major }}
7392
- run: yarn test:integration:playwright
7493
env:
7594
NODE_OPTIONS: '-r ./ci/init'

integration-tests/ci-visibility/web-app-server-with-redirect.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
// File to spin an HTTP server that returns an HTML for playwright to visit
44
const http = require('http')
55

6-
module.exports = http.createServer((req, res) => {
7-
res.setHeader('Content-Type', 'text/html')
8-
res.writeHead(200)
9-
res.end(`
10-
<!DOCTYPE html>
11-
<meta http-equiv="refresh" content="0; url=https://playwright.dev/" />
12-
`)
13-
})
6+
function createWebAppServerWithRedirect () {
7+
return http.createServer((req, res) => {
8+
res.setHeader('Content-Type', 'text/html')
9+
res.writeHead(200)
10+
res.end(`
11+
<!DOCTYPE html>
12+
<meta http-equiv="refresh" content="0; url=https://playwright.dev/" />
13+
`)
14+
})
15+
}
16+
17+
// For backward compatibility, export a default instance
18+
module.exports = createWebAppServerWithRedirect()
19+
// Also export the factory function for creating fresh instances
20+
module.exports.createWebAppServerWithRedirect = createWebAppServerWithRedirect

integration-tests/playwright/playwright.spec.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const {
1515
getCiVisEvpProxyConfig
1616
} = require('../helpers')
1717
const { FakeCiVisIntake } = require('../ci-visibility-intake')
18-
const webAppServer = require('../ci-visibility/web-app-server')
19-
const webAppServerWithRedirect = require('../ci-visibility/web-app-server-with-redirect')
18+
const { createWebAppServer } = require('../ci-visibility/web-app-server')
19+
const { createWebAppServerWithRedirect } = require('../ci-visibility/web-app-server-with-redirect')
2020
const {
2121
TEST_STATUS,
2222
TEST_SOURCE_START,
@@ -78,22 +78,38 @@ versions.forEach((version) => {
7878
}
7979

8080
describe(`playwright@${version}`, function () {
81-
let cwd, receiver, childProcess, webAppPort, webPortWithRedirect
81+
let cwd, receiver, childProcess, webAppPort, webPortWithRedirect, webAppServer, webAppServerWithRedirect
8282

8383
this.retries(2)
8484
this.timeout(80000)
8585

8686
useSandbox([`@playwright/test@${version}`, 'typescript'], true)
8787

8888
before(function (done) {
89+
// Increase timeout for this hook specifically to account for slow chromium installation in CI
90+
this.timeout(120000)
91+
8992
cwd = sandboxCwd()
9093
const { NODE_OPTIONS, ...restOfEnv } = process.env
9194
// Install chromium (configured in integration-tests/playwright.config.js)
9295
// *Be advised*: this means that we'll only be using chromium for this test suite
96+
// This will use cached browsers if available, otherwise download
9397
execSync('npx playwright install chromium', { cwd, env: restOfEnv, stdio: 'inherit' })
94-
webAppServer.listen(0, () => {
98+
99+
// Create fresh server instances to avoid issues with retries
100+
webAppServer = createWebAppServer()
101+
webAppServerWithRedirect = createWebAppServerWithRedirect()
102+
103+
webAppServer.listen(0, (err) => {
104+
if (err) {
105+
return done(err)
106+
}
95107
webAppPort = webAppServer.address().port
96-
webAppServerWithRedirect.listen(0, () => {
108+
109+
webAppServerWithRedirect.listen(0, (err) => {
110+
if (err) {
111+
return done(err)
112+
}
97113
webPortWithRedirect = webAppServerWithRedirect.address().port
98114
done()
99115
})

0 commit comments

Comments
 (0)