Unverified Commit 53d017d3 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Parallelize dev/start flake detection (#63954)

Since we're re-running tests a few times and in both modes this can take
a while ([related
run](https://github.com/vercel/next.js/actions/runs/8514892757/job/23321431099?pr=56995)),
so this parallelizes by separating dev/prod into separate jobs.

Closes NEXT-2975
parent fbfd1b27
......@@ -256,15 +256,27 @@ jobs:
secrets: inherit
test-new-tests:
name: Test new tests for flakes
test-new-tests-dev:
name: Test new tests for flakes (dev)
needs: ['changes', 'build-native', 'build-next']
if: ${{ needs.changes.outputs.docs-only == 'false' }}
uses: ./.github/workflows/build_reusable.yml
with:
afterBuild: node scripts/test-new-tests.mjs
stepName: 'test-new-tests'
afterBuild: node scripts/test-new-tests.mjs --dev-mode
stepName: 'test-new-tests-dev'
secrets: inherit
test-new-tests-start:
name: Test new tests for flakes (prod)
needs: ['changes', 'build-native', 'build-next']
if: ${{ needs.changes.outputs.docs-only == 'false' }}
uses: ./.github/workflows/build_reusable.yml
with:
afterBuild: node scripts/test-new-tests.mjs --prod-mode
stepName: 'test-new-tests-start'
secrets: inherit
......
......@@ -4,6 +4,8 @@ import execa from 'execa'
import path from 'path'
async function main() {
let testMode = process.argv.includes('--dev-mode') ? 'dev' : 'start'
let eventData = {}
/** @type import('execa').Options */
......@@ -57,6 +59,7 @@ async function main() {
branchName,
remoteUrl,
isCanary,
testMode,
},
`\ngit diff:\n${changesResult.stderr}\n${changesResult.stdout}`
)
......@@ -99,42 +102,25 @@ async function main() {
)
)
if (prodTests.length === 0 && devTests.length === 0) {
const currentTests = testMode === 'dev' ? devTests : prodTests
if (currentTests.length === 0) {
console.log(`No added/changed tests detected`)
return
}
const RUN_TESTS_ARGS = ['run-tests.js', '-c', '1', '--retries', '0']
async function invokeRunTests({ mode, testFiles }) {
await execa('node', [...RUN_TESTS_ARGS, ...testFiles], {
for (let i = 0; i < 3; i++) {
console.log(`\n\nRun ${i + 1} for ${testMode} tests`)
await execa('node', [...RUN_TESTS_ARGS, ...currentTests], {
...EXECA_OPTS_STDIO,
env: {
...process.env,
NEXT_TEST_MODE: mode,
NEXT_TEST_MODE: testMode,
},
})
}
if (devTests.length > 0) {
for (let i = 0; i < 3; i++) {
console.log(`\n\nRun ${i + 1} for dev tests`)
await invokeRunTests({
mode: 'dev',
testFiles: devTests,
})
}
}
if (prodTests.length > 0) {
for (let i = 0; i < 3; i++) {
console.log(`\n\nRun ${i + 1} for production tests`)
await invokeRunTests({
mode: 'start',
testFiles: prodTests,
})
}
}
}
main().catch((err) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment