Auto-retry starting app in mock tests
This commit is contained in:
parent
7419ef9bd5
commit
d6cc067507
1 changed files with 28 additions and 14 deletions
|
@ -63,6 +63,8 @@ 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;
|
||||||
|
@ -260,7 +262,7 @@ export class Bootstrap {
|
||||||
await app.close();
|
await app.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async startApp(): Promise<App> {
|
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()'
|
||||||
|
@ -269,22 +271,34 @@ export class Bootstrap {
|
||||||
debug('starting the app');
|
debug('starting the app');
|
||||||
|
|
||||||
const { port } = this.server.address();
|
const { port } = this.server.address();
|
||||||
|
const config = await this.generateConfig(port);
|
||||||
|
|
||||||
const app = new App({
|
let app: App | undefined;
|
||||||
|
while (!app) {
|
||||||
|
const startedApp = new App({
|
||||||
main: ELECTRON,
|
main: ELECTRON,
|
||||||
args: [CI_SCRIPT],
|
args: [CI_SCRIPT],
|
||||||
config: await this.generateConfig(port),
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
await app.start();
|
this.lastApp = startedApp;
|
||||||
|
startedApp.on('close', () => {
|
||||||
this.lastApp = app;
|
if (this.lastApp === startedApp) {
|
||||||
app.on('close', () => {
|
|
||||||
if (this.lastApp === app) {
|
|
||||||
this.lastApp = undefined;
|
this.lastApp = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app = startedApp;
|
||||||
|
}
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue