Skip to content

Commit 3cd85ab

Browse files
committed
chore: experiment with running Platform tests in parallel
1 parent 7869d4b commit 3cd85ab

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

test/e2e/run.mjs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ process.env.STORAGE_IMPLEMENTATION ??= 'MEMORY';
3030
// so that the CI knows that e2e test suite has failed
3131
let failure = false;
3232

33-
async function run() {
33+
async function run({ maxParallelTests = 1 } = {}) {
3434
if (!['LOCAL', 'MEMORY', 'PLATFORM'].includes(process.env.STORAGE_IMPLEMENTATION)) {
3535
throw new Error(`Unknown storage provided: '${process.env.STORAGE_IMPLEMENTATION}'`);
3636
}
@@ -40,9 +40,23 @@ async function run() {
4040
const paths = await readdir(basePath, { withFileTypes: true });
4141
const dirs = paths.filter((dirent) => dirent.isDirectory());
4242

43-
for (const dir of dirs) {
43+
const concurrentGroups = dirs.reduce((groups, dir, index) => {
44+
const groupIndex = Math.floor(index / maxParallelTests);
45+
if (!groups[groupIndex]) {
46+
groups[groupIndex] = [];
47+
}
48+
groups[groupIndex].push(dir);
49+
return groups;
50+
}, []);
51+
52+
for (const group of concurrentGroups) {
53+
const promises = group.map((dir) => runTest(dir));
54+
await Promise.all(promises);
55+
}
56+
57+
async function runTest(dir) {
4458
if (process.argv.length === 3 && dir.name !== process.argv[2]) {
45-
continue;
59+
return;
4660
}
4761

4862
const now = Date.now();
@@ -51,6 +65,7 @@ async function run() {
5165
stdout: true,
5266
stderr: true,
5367
});
68+
const logLines = [];
5469
let seenFirst = false;
5570
/** @type Map<string, string[]> */
5671
const allLogs = new Map();
@@ -91,22 +106,22 @@ async function run() {
91106
) {
92107
const platformStatsMessage = str.match(/\[(?:run|build|kv)] (.*)/);
93108
if (platformStatsMessage) {
94-
console.log(`${colors.yellow(`[${dir.name}] `)}${colors.grey(platformStatsMessage[1])}`);
109+
logLines.push(`${colors.yellow(`[${dir.name}] `)}${colors.grey(platformStatsMessage[1])}`);
95110
}
96111
}
97112

98113
const match = str.match(/\[assertion] (passed|failed): (.*)/);
99114

100115
if (match) {
101116
const c = match[1] === 'passed' ? colors.green : colors.red;
102-
console.log(`${colors.yellow(`[${dir.name}] `)}${match[2]}: ${c(match[1])}`);
117+
logLines.push(`${colors.yellow(`[${dir.name}] `)}${match[2]}: ${c(match[1])}`);
103118
}
104119
});
105120

106121
worker.on('error', (err) => {
107122
// If the worker emits any error, we want to exit with a non-zero code
108123
failure = true;
109-
console.log(`${colors.red('[fatal]')} test ${colors.yellow(`[${dir.name}]`)} failed with error: ${err}`);
124+
logLines.push(`${colors.red('[fatal]')} test ${colors.yellow(`[${dir.name}]`)} failed with error: ${err}`);
110125
});
111126

112127
const exitHandler = async (code) => {
@@ -118,7 +133,7 @@ async function run() {
118133
const took = (Date.now() - now) / 1000;
119134
const status = code === 0 ? 'success' : 'failure';
120135
const color = code === 0 ? 'green' : 'red';
121-
console.log(
136+
logLines.push(
122137
`${colors.yellow(`[${dir.name}] `)}${colors[color](
123138
`Test finished with status: ${status} `,
124139
)}${colors.grey(`[took ${took}s]`)}`,
@@ -135,7 +150,7 @@ async function run() {
135150
const taskLogs = allLogs.get(dir.name);
136151

137152
if (code !== 0 && taskLogs?.length > 0) {
138-
console.log(taskLogs.join('\n'));
153+
logLines.push(taskLogs.join('\n'));
139154
}
140155

141156
if (status === 'failure') failure = true;
@@ -147,6 +162,7 @@ async function run() {
147162
try {
148163
await exitHandler(exitCode);
149164
} finally {
165+
console.log(logLines.join('\n'));
150166
markTestDone();
151167
}
152168
});
@@ -168,7 +184,7 @@ if (isMainThread) {
168184
console.log('Fetching camoufox');
169185
execSync(`npx camoufox-js fetch`, { stdio: 'inherit' });
170186
}
171-
await run();
187+
await run({ maxParallelTests: process.env.STORAGE_IMPLEMENTATION === 'PLATFORM' ? 10 : 1 });
172188
} catch (e) {
173189
failure = true;
174190
console.error(e);

0 commit comments

Comments
 (0)