Prevent (some) CI flakes

This commit is contained in:
trevor-signal 2023-12-01 17:16:19 -05:00 committed by GitHub
parent b879352096
commit 582a56f52d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 19 deletions

View file

@ -63,8 +63,6 @@ for (const firstName of CONTACT_FIRST_NAMES) {
const MAX_CONTACTS = CONTACT_NAMES.length; const MAX_CONTACTS = CONTACT_NAMES.length;
const DEFAULT_START_APP_TIMEOUT = 10 * durations.SECOND;
export type BootstrapOptions = Readonly<{ export type BootstrapOptions = Readonly<{
extraConfig?: Record<string, unknown>; extraConfig?: Record<string, unknown>;
benchmark?: boolean; benchmark?: boolean;
@ -268,12 +266,7 @@ export class Bootstrap {
await app.close(); await app.close();
} }
private async waitForAppToStart(app: App): Promise<void> { public async startApp(): Promise<App> {
await app.start();
await app.waitForDbInitialized();
}
public async startApp(timeout = DEFAULT_START_APP_TIMEOUT): Promise<App> {
assert( assert(
this.storagePath !== undefined, this.storagePath !== undefined,
'Bootstrap has to be initialized first, see: bootstrap.init()' 'Bootstrap has to be initialized first, see: bootstrap.init()'
@ -301,11 +294,11 @@ export class Bootstrap {
}); });
try { try {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await pTimeout(this.waitForAppToStart(startedApp), timeout); await startedApp.start();
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error( console.error(
`Failed to start the app on time, attempt ${startAttempts}, retrying`, `Failed to start the app, attempt ${startAttempts}, retrying`,
error error
); );
continue; continue;
@ -440,6 +433,9 @@ export class Bootstrap {
try { try {
await pTimeout(fn(bootstrap), timeout); await pTimeout(fn(bootstrap), timeout);
if (process.env.FORCE_ARTIFACT_SAVE) {
await bootstrap.saveLogs();
}
} catch (error) { } catch (error) {
await bootstrap.saveLogs(); await bootstrap.saveLogs();
throw error; throw error;

View file

@ -4,6 +4,7 @@
import type { ElectronApplication, Locator, Page } from 'playwright'; import type { ElectronApplication, Locator, Page } from 'playwright';
import { _electron as electron } from 'playwright'; import { _electron as electron } from 'playwright';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import pTimeout from 'p-timeout';
import type { import type {
IPCRequest as ChallengeRequestType, IPCRequest as ChallengeRequestType,
@ -51,15 +52,31 @@ export class App extends EventEmitter {
} }
public async start(): Promise<void> { public async start(): Promise<void> {
this.privApp = await electron.launch({ try {
executablePath: this.options.main, // launch the electron processs
args: this.options.args.slice(), this.privApp = await electron.launch({
env: { executablePath: this.options.main,
...process.env, args: this.options.args.slice(),
SIGNAL_CI_CONFIG: this.options.config, env: {
}, ...process.env,
locale: 'en', SIGNAL_CI_CONFIG: this.options.config,
}); },
locale: 'en',
timeout: 20 * SECOND,
});
// wait for the first window to load
await pTimeout(
(async () => {
const page = await this.privApp?.firstWindow();
await page?.waitForLoadState('load');
})(),
20 * SECOND
);
} catch (e) {
this.privApp?.process().kill('SIGKILL');
throw e;
}
this.privApp.on('close', () => this.emit('close')); this.privApp.on('close', () => this.emit('close'));
} }