From 582a56f52d98c5be8bfa0fa8c71518929d7ab2e3 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Fri, 1 Dec 2023 17:16:19 -0500 Subject: [PATCH] Prevent (some) CI flakes --- ts/test-mock/bootstrap.ts | 16 ++++++---------- ts/test-mock/playwright.ts | 35 ++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/ts/test-mock/bootstrap.ts b/ts/test-mock/bootstrap.ts index 8909271e6a..f7ebca3c55 100644 --- a/ts/test-mock/bootstrap.ts +++ b/ts/test-mock/bootstrap.ts @@ -63,8 +63,6 @@ for (const firstName of CONTACT_FIRST_NAMES) { const MAX_CONTACTS = CONTACT_NAMES.length; -const DEFAULT_START_APP_TIMEOUT = 10 * durations.SECOND; - export type BootstrapOptions = Readonly<{ extraConfig?: Record; benchmark?: boolean; @@ -268,12 +266,7 @@ export class Bootstrap { await app.close(); } - private async waitForAppToStart(app: App): Promise { - await app.start(); - await app.waitForDbInitialized(); - } - - public async startApp(timeout = DEFAULT_START_APP_TIMEOUT): Promise { + public async startApp(): Promise { assert( this.storagePath !== undefined, 'Bootstrap has to be initialized first, see: bootstrap.init()' @@ -301,11 +294,11 @@ export class Bootstrap { }); try { // eslint-disable-next-line no-await-in-loop - await pTimeout(this.waitForAppToStart(startedApp), timeout); + await startedApp.start(); } catch (error) { // eslint-disable-next-line no-console console.error( - `Failed to start the app on time, attempt ${startAttempts}, retrying`, + `Failed to start the app, attempt ${startAttempts}, retrying`, error ); continue; @@ -440,6 +433,9 @@ export class Bootstrap { try { await pTimeout(fn(bootstrap), timeout); + if (process.env.FORCE_ARTIFACT_SAVE) { + await bootstrap.saveLogs(); + } } catch (error) { await bootstrap.saveLogs(); throw error; diff --git a/ts/test-mock/playwright.ts b/ts/test-mock/playwright.ts index cf9fb5b26e..b82185271a 100644 --- a/ts/test-mock/playwright.ts +++ b/ts/test-mock/playwright.ts @@ -4,6 +4,7 @@ import type { ElectronApplication, Locator, Page } from 'playwright'; import { _electron as electron } from 'playwright'; import { EventEmitter } from 'events'; +import pTimeout from 'p-timeout'; import type { IPCRequest as ChallengeRequestType, @@ -51,15 +52,31 @@ export class App extends EventEmitter { } public async start(): Promise { - this.privApp = await electron.launch({ - executablePath: this.options.main, - args: this.options.args.slice(), - env: { - ...process.env, - SIGNAL_CI_CONFIG: this.options.config, - }, - locale: 'en', - }); + try { + // launch the electron processs + this.privApp = await electron.launch({ + executablePath: this.options.main, + args: this.options.args.slice(), + env: { + ...process.env, + 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')); }