Mock tests: retry app launch until DB initializes

This commit is contained in:
trevor-signal 2023-10-30 15:27:29 -04:00 committed by GitHub
parent 6bd802a03d
commit 47aff178da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 24 additions and 24 deletions

View file

@ -1008,6 +1008,8 @@ async function createWindow() {
return;
}
mainWindow.webContents.send('ci:event', 'db-initialized', {});
const shouldShowWindow =
!app.getLoginItemSettings().wasOpenedAsHidden && !startInTray;

View file

@ -268,6 +268,11 @@ export class Bootstrap {
await app.close();
}
private async waitForAppToStart(app: App): Promise<void> {
await app.start();
await app.waitForDbInitialized();
}
public async startApp(timeout = DEFAULT_START_APP_TIMEOUT): Promise<App> {
assert(
this.storagePath !== undefined,
@ -279,8 +284,16 @@ export class Bootstrap {
const { port } = this.server.address();
const config = await this.generateConfig(port);
let startAttempts = 0;
const MAX_ATTEMPTS = 5;
let app: App | undefined;
while (!app) {
startAttempts += 1;
if (startAttempts > MAX_ATTEMPTS) {
throw new Error(
`App failed to start after ${MAX_ATTEMPTS} times, giving up`
);
}
const startedApp = new App({
main: ELECTRON,
args: [CI_SCRIPT],
@ -288,10 +301,13 @@ export class Bootstrap {
});
try {
// eslint-disable-next-line no-await-in-loop
await pTimeout(startedApp.start(), timeout);
await pTimeout(this.waitForAppToStart(startedApp), timeout);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to start the app on time, retrying', error);
console.error(
`Failed to start the app on time, attempt ${startAttempts}, retrying`,
error
);
continue;
}

View file

@ -88,7 +88,6 @@ function createEditedMessage(
describe('editing', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -13,7 +13,6 @@ export const debug = createDebug('mock:test:readSync');
describe('readSync', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -13,7 +13,6 @@ export const debug = createDebug('mock:test:senderKey');
describe('senderKey', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -22,7 +22,6 @@ const DISTRIBUTION2 = generateStoryDistributionId();
describe('story/messaging', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -14,7 +14,6 @@ export const debug = createDebug('mock:test:edit');
describe('unknown contacts', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -81,6 +81,10 @@ export class App extends EventEmitter {
return this.waitForEvent('provisioning-url');
}
public async waitForDbInitialized(): Promise<void> {
return this.waitForEvent('db-initialized');
}
public async waitUntilLoaded(): Promise<AppLoadedInfoType> {
return this.waitForEvent('app-loaded');
}

View file

@ -14,7 +14,6 @@ export const debug = createDebug('mock:test:gv2');
describe('pnp/accept gv2 invite', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -12,7 +12,6 @@ export const debug = createDebug('mock:test:change-number');
describe('pnp/change number', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -20,7 +20,6 @@ const IdentifierType = Proto.ManifestRecord.Identifier.Type;
describe('pnp/merge', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -20,7 +20,6 @@ const IdentifierType = Proto.ManifestRecord.Identifier.Type;
// PhoneNumberDiscovery notifications are also known as a Session Switchover Events (SSE).
describe('pnp/phone discovery', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -18,7 +18,6 @@ export const debug = createDebug('mock:test:pni-change');
// https://github.com/signalapp/Signal-Android-Private/blob/df83c941804512c613a1010b7d8e5ce4f0aec71c/app/src/androidTest/java/org/thoughtcrime/securesms/database/RecipientTableTest_getAndPossiblyMerge.kt#L266-L270
describe('pnp/PNI Change', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -25,7 +25,6 @@ const IdentifierType = Proto.ManifestRecord.Identifier.Type;
describe('pnp/PNI Signature', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -20,7 +20,6 @@ export const debug = createDebug('mock:test:pni-unlink');
describe('pnp/PNI DecryptionError unlink', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App | undefined;

View file

@ -18,7 +18,6 @@ export const debug = createDebug('mock:test:gv2');
describe('pnp/send gv2 invite', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -25,7 +25,6 @@ const CARL_USERNAME = 'carl.84';
describe('pnp/username', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -17,7 +17,6 @@ const IdentifierType = Proto.ManifestRecord.Identifier.Type;
describe('story/no-sender-key', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -15,7 +15,6 @@ export const debug = createDebug('mock:test:challenge:receipts');
describe('challenge/receipts', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -9,7 +9,6 @@ import { initStorage, debug } from './fixtures';
describe('storage service', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -12,7 +12,6 @@ const IdentifierType = Proto.ManifestRecord.Identifier.Type;
describe('storage service', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -14,7 +14,6 @@ const IdentifierType = Proto.ManifestRecord.Identifier.Type;
describe('storage service', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -9,7 +9,6 @@ import { initStorage, debug } from './fixtures';
describe('storage service', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -12,7 +12,6 @@ import { initStorage, debug } from './fixtures';
describe('storage service', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;

View file

@ -64,7 +64,6 @@ function getStickerPackRecordPredicate(
describe('storage service', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
this.retries(4);
let bootstrap: Bootstrap;
let app: App;