Retry test-electron in case of SIGBUS

This commit is contained in:
trevor-signal 2023-12-07 20:54:33 -05:00 committed by GitHub
parent b80b9c962d
commit b089eef942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,24 +13,51 @@ const ELECTRON = join(
process.platform === 'win32' ? 'electron.cmd' : 'electron' process.platform === 'win32' ? 'electron.cmd' : 'electron'
); );
let stdout: string; const MAX_RETRIES = 3;
try { const RETRIABLE_SIGNALS = ['SIGBUS'];
stdout = execFileSync(ELECTRON, [ROOT_DIR], {
cwd: ROOT_DIR, function launchElectron(attempt: number): string {
env: { if (attempt > MAX_RETRIES) {
...process.env, console.error(`Failed after ${MAX_RETRIES} retries, exiting.`);
NODE_ENV: 'test', process.exit(1);
TEST_QUIT_ON_COMPLETE: 'on', }
},
encoding: 'utf8', console.log(`Launching electron for tests, attempt #${attempt}...`);
});
} catch (error) { try {
console.error('Status', error.status); const stdout = execFileSync(ELECTRON, [ROOT_DIR], {
console.error(error.output[0] ?? ''); cwd: ROOT_DIR,
console.error(error.output[1] ?? ''); env: {
process.exit(1); ...process.env,
// Setting node_env to test triggers main.ts to load 'test/index.html' instead of
// 'background.html', which loads the tests via `test.js`
NODE_ENV: 'test',
TEST_QUIT_ON_COMPLETE: 'on',
},
encoding: 'utf8',
});
return stdout;
} catch (error) {
console.error('Status', error.status);
// In testing, error.signal is null, so we need to read it from stderr
const signalMatch = error.stderr.match(/exited with signal (\w+)/);
const signal = error.signal || signalMatch?.[1];
console.error('Signal', signal);
console.error(error.output[0] ?? '');
console.error(error.output[1] ?? '');
if (RETRIABLE_SIGNALS.includes(signal)) {
return launchElectron(attempt + 1);
}
process.exit(1);
}
} }
const stdout = launchElectron(1);
const debugMatch = stdout.matchAll(/ci:test-electron:debug=(.*)?\n/g); const debugMatch = stdout.matchAll(/ci:test-electron:debug=(.*)?\n/g);
Array.from(debugMatch).forEach(info => { Array.from(debugMatch).forEach(info => {
try { try {