diff --git a/ts/test-mock/bootstrap.ts b/ts/test-mock/bootstrap.ts index faf9f31e2..86e889397 100644 --- a/ts/test-mock/bootstrap.ts +++ b/ts/test-mock/bootstrap.ts @@ -63,6 +63,8 @@ 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; @@ -260,7 +262,7 @@ export class Bootstrap { await app.close(); } - public async startApp(): Promise { + public async startApp(timeout = DEFAULT_START_APP_TIMEOUT): Promise { assert( this.storagePath !== undefined, 'Bootstrap has to be initialized first, see: bootstrap.init()' @@ -269,21 +271,33 @@ export class Bootstrap { debug('starting the app'); const { port } = this.server.address(); + const config = await this.generateConfig(port); - const app = new App({ - main: ELECTRON, - args: [CI_SCRIPT], - config: await this.generateConfig(port), - }); - - await app.start(); - - this.lastApp = app; - app.on('close', () => { - if (this.lastApp === app) { - this.lastApp = undefined; + let app: App | undefined; + while (!app) { + const startedApp = new App({ + main: ELECTRON, + args: [CI_SCRIPT], + config, + }); + try { + // eslint-disable-next-line no-await-in-loop + await pTimeout(startedApp.start(), timeout); + } catch (error) { + // eslint-disable-next-line no-console + console.error('Failed to start the app on time, retrying', error); + continue; } - }); + + this.lastApp = startedApp; + startedApp.on('close', () => { + if (this.lastApp === startedApp) { + this.lastApp = undefined; + } + }); + + app = startedApp; + } return app; }