Skip to content

Commit aca5249

Browse files
authored
ci: Improve flaky test detector performance (#7569)
We now run all tests into a single spawned process, which should hopefully speed this up a bit. We also reduce the # of repetitions from 100 to 50 to ensure we do not run overtime.
1 parent 8e78e6e commit aca5249

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

.github/workflows/flaky-test-detector.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ jobs:
7777
working-directory: packages/browser-integration-tests
7878
env:
7979
CHANGED_TEST_PATHS: ${{ steps.changed.outputs.browser_integration_files }}
80-
# Run 100 times when detecting changed test(s), else run all tests 5x
81-
TEST_RUN_COUNT: ${{ steps.changed.outputs.browser_integration == 'true' && 100 || 5 }}
80+
# Run 50 times when detecting changed test(s), else run all tests 5x
81+
TEST_RUN_COUNT: ${{ steps.changed.outputs.browser_integration == 'true' && 50 || 5 }}

packages/browser-integration-tests/scripts/detectFlakyTests.ts

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,72 @@ import { promisify } from 'util';
66
const exec = promisify(childProcess.exec);
77

88
async function run(): Promise<void> {
9-
let testPaths = getTestPaths();
10-
let failed = [];
9+
let testPaths: string[] = [];
1110

12-
try {
13-
const changedPaths: string[] = process.env.CHANGED_TEST_PATHS ? JSON.parse(process.env.CHANGED_TEST_PATHS) : [];
11+
const changedPaths: string[] = process.env.CHANGED_TEST_PATHS ? JSON.parse(process.env.CHANGED_TEST_PATHS) : [];
1412

15-
if (changedPaths.length > 0) {
16-
console.log(`Detected changed test paths:
13+
if (changedPaths.length > 0) {
14+
console.log(`Detected changed test paths:
1715
${changedPaths.join('\n')}
1816
1917
`);
2018

21-
testPaths = testPaths.filter(p => changedPaths.some(changedPath => changedPath.includes(p)));
19+
testPaths = getTestPaths().filter(p => changedPaths.some(changedPath => changedPath.includes(p)));
20+
if (testPaths.length === 0) {
21+
console.log('Could not find matching tests, aborting...');
22+
process.exit(1);
2223
}
23-
} catch {
24-
console.log('Could not detect changed test paths, running all tests.');
2524
}
2625

2726
const cwd = path.join(__dirname, '../');
2827
const runCount = parseInt(process.env.TEST_RUN_COUNT || '10');
2928

30-
for (const testPath of testPaths) {
31-
console.log(`Running test: ${testPath}`);
32-
const start = Date.now();
29+
try {
30+
await new Promise<void>((resolve, reject) => {
31+
const cp = childProcess.spawn(
32+
`yarn playwright test ${
33+
testPaths.length ? testPaths.join(' ') : './suites'
34+
} --browser='all' --reporter='line' --repeat-each ${runCount}`,
35+
{ shell: true, cwd },
36+
);
37+
38+
let error: Error | undefined;
39+
40+
cp.stdout.on('data', data => {
41+
console.log(data ? (data as object).toString() : '');
42+
});
3343

34-
try {
35-
await exec(`yarn playwright test ${testPath} --browser='all' --repeat-each ${runCount}`, {
36-
cwd,
44+
cp.stderr.on('data', data => {
45+
console.log(data ? (data as object).toString() : '');
3746
});
38-
const end = Date.now();
39-
console.log(` ☑️ Passed ${runCount} times, avg. duration ${Math.ceil((end - start) / runCount)}ms`);
40-
} catch (error) {
41-
logError(error);
42-
failed.push(testPath);
43-
}
44-
}
4547

46-
console.log('');
47-
console.log('');
48+
cp.on('error', e => {
49+
console.error(e);
50+
error = e;
51+
});
4852

49-
if (failed.length > 0) {
50-
console.error(`⚠️ ${failed.length} test(s) failed.`);
53+
cp.on('close', status => {
54+
const err = error || (status !== 0 ? new Error(`Process exited with status ${status}`) : undefined);
55+
56+
if (err) {
57+
reject(err);
58+
} else {
59+
resolve();
60+
}
61+
});
62+
});
63+
} catch (error) {
64+
console.log('');
65+
console.log('');
66+
67+
console.error(`⚠️ Some tests failed.`);
68+
console.error(error);
5169
process.exit(1);
52-
} else {
53-
console.log(`☑️ ${testPaths.length} test(s) passed.`);
5470
}
71+
72+
console.log('');
73+
console.log('');
74+
console.log(`☑️ All tests passed.`);
5575
}
5676

5777
function getTestPaths(): string[] {

0 commit comments

Comments
 (0)