Skip to content

Commit 9b3d7fd

Browse files
[test optimization] Improve flakiness of performance overhead test (#5898)
1 parent e9b2b58 commit 9b3d7fd

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

.github/workflows/test-optimization.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
with:
3030
token: ${{ steps.app-token.outputs.token }}
3131
- uses: ./.github/actions/node/oldest-maintenance-lts
32-
- name: CI Visibility Performance Overhead Test
33-
run: yarn bench:e2e:ci-visibility
32+
- name: Test Optimization Performance Overhead Test
33+
run: yarn bench:e2e:test-optimization
3434
env:
3535
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
3636

benchmark/e2e-ci/benchmark-run.js renamed to benchmark/e2e-test-optimization/benchmark-run.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
/* eslint-disable no-console */
44

55
const https = require('https')
6+
const { setTimeout } = require('timers/promises')
67

78
const API_REPOSITORY_URL = 'https://api.github.com/repos/DataDog/test-environment'
89
const DISPATCH_WORKFLOW_URL = `${API_REPOSITORY_URL}/actions/workflows/dd-trace-js-tests.yml/dispatches`
910
const GET_WORKFLOWS_URL = `${API_REPOSITORY_URL}/actions/runs`
1011

12+
const MAX_ATTEMPTS = 30 * 60 / 5 // 30 minutes, polling every 5 seconds = 360 attempts
13+
1114
function getBranchUnderTest () {
1215
/**
1316
* GITHUB_HEAD_REF is only set for `pull_request` events
@@ -106,17 +109,9 @@ const getCurrentWorkflowJobs = (runId) => {
106109
})
107110
}
108111

109-
const wait = (timeToWaitMs) => {
110-
return new Promise(resolve => {
111-
setTimeout(() => {
112-
resolve()
113-
}, timeToWaitMs)
114-
})
115-
}
116-
117112
async function main () {
118113
// Trigger JS GHA
119-
console.log('Triggering CI Visibility test environment workflow.')
114+
console.log('Triggering Test Optimization test environment workflow.')
120115
const httpResponseCode = await triggerWorkflow()
121116
console.log('GitHub API response code:', httpResponseCode)
122117

@@ -125,7 +120,7 @@ async function main () {
125120
}
126121

127122
// Give some time for GH to process the request
128-
await wait(15000)
123+
await setTimeout(15000)
129124

130125
// Get the run ID from the workflow we just triggered
131126
const workflowsInProgress = await getWorkflowRunsInProgress()
@@ -143,30 +138,35 @@ async function main () {
143138
console.log(`Workflow URL: https://github.com/DataDog/test-environment/actions/runs/${runId}`)
144139

145140
// Wait an initial 1 minute, because we're sure it won't finish earlier
146-
await wait(60000)
147-
148-
// Poll every 5 seconds until we have a finished status
149-
await new Promise((resolve, reject) => {
150-
const intervalId = setInterval(async () => {
151-
const currentWorkflow = await getCurrentWorkflowJobs(runId)
152-
const { jobs } = currentWorkflow
153-
const hasAnyJobFailed = jobs.some(({ status, conclusion }) => status === 'completed' && conclusion !== 'success')
154-
const hasEveryJobPassed = jobs.every(
155-
({ status, conclusion }) => status === 'completed' && conclusion === 'success'
156-
)
157-
if (hasAnyJobFailed) {
158-
reject(new Error(`Performance overhead test failed.
159-
Check https://github.com/DataDog/test-environment/actions/runs/${runId} for more details.`))
160-
clearInterval(intervalId)
161-
} else if (hasEveryJobPassed) {
162-
console.log('Performance overhead test successful.')
163-
resolve()
164-
clearInterval(intervalId)
165-
} else {
166-
console.log(`Workflow https://github.com/DataDog/test-environment/actions/runs/${runId} is not finished yet.`)
167-
}
168-
}, 5000)
169-
})
141+
await setTimeout(60000)
142+
143+
// Poll every 5 seconds until we have a finished status, up to 30 minutes
144+
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
145+
const currentWorkflow = await getCurrentWorkflowJobs(runId)
146+
const { jobs } = currentWorkflow
147+
if (!jobs) {
148+
console.error('Workflow check returned unknown object %o. Retry in 5 seconds.', currentWorkflow)
149+
await setTimeout(5000)
150+
continue
151+
}
152+
const hasAnyJobFailed = jobs
153+
.some(({ status, conclusion }) => status === 'completed' && conclusion !== 'success')
154+
const hasEveryJobPassed = jobs.every(
155+
({ status, conclusion }) => status === 'completed' && conclusion === 'success'
156+
)
157+
if (hasAnyJobFailed) {
158+
throw new Error(`Performance overhead test failed.\n Check https://github.com/DataDog/test-environment/actions/runs/${runId} for more details.`)
159+
} else if (hasEveryJobPassed) {
160+
console.log('Performance overhead test successful.')
161+
break
162+
} else {
163+
console.log(`Workflow https://github.com/DataDog/test-environment/actions/runs/${runId} is not finished yet. [Attempt ${attempt + 1}/${MAX_ATTEMPTS}]`)
164+
}
165+
if (attempt === MAX_ATTEMPTS - 1) {
166+
throw new Error(`Timeout: Workflow did not finish within 30 minutes. Check https://github.com/DataDog/test-environment/actions/runs/${runId} for more details.`)
167+
}
168+
await setTimeout(5000)
169+
}
170170
}
171171

172172
main().catch(e => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"env": "bash ./plugin-env",
99
"preinstall": "node scripts/preinstall.js",
1010
"bench": "node benchmark/index.js",
11-
"bench:e2e:ci-visibility": "node benchmark/e2e-ci/benchmark-run.js",
11+
"bench:e2e:test-optimization": "node benchmark/e2e-test-optimization/benchmark-run.js",
1212
"dependencies:dedupe": "yarn-deduplicate yarn.lock",
1313
"type:doc": "cd docs && yarn && yarn build",
1414
"type:test": "cd docs && yarn && yarn test",

0 commit comments

Comments
 (0)