diff --git a/app/main.ts b/app/main.ts index e46822a85a..a68dbdafe8 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1008,6 +1008,8 @@ async function createWindow() { return; } + mainWindow.webContents.send('ci:event', 'db-initialized', {}); + const shouldShowWindow = !app.getLoginItemSettings().wasOpenedAsHidden && !startInTray; diff --git a/ts/test-mock/bootstrap.ts b/ts/test-mock/bootstrap.ts index 127e43c34e..8909271e6a 100644 --- a/ts/test-mock/bootstrap.ts +++ b/ts/test-mock/bootstrap.ts @@ -268,6 +268,11 @@ 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 { 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; } diff --git a/ts/test-mock/messaging/edit_test.ts b/ts/test-mock/messaging/edit_test.ts index 485f60ed51..22a5087888 100644 --- a/ts/test-mock/messaging/edit_test.ts +++ b/ts/test-mock/messaging/edit_test.ts @@ -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; diff --git a/ts/test-mock/messaging/readSync_test.ts b/ts/test-mock/messaging/readSync_test.ts index 4d19e12815..84eaedda42 100644 --- a/ts/test-mock/messaging/readSync_test.ts +++ b/ts/test-mock/messaging/readSync_test.ts @@ -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; diff --git a/ts/test-mock/messaging/sender_key_test.ts b/ts/test-mock/messaging/sender_key_test.ts index d837c6f06e..8dfb02fe82 100644 --- a/ts/test-mock/messaging/sender_key_test.ts +++ b/ts/test-mock/messaging/sender_key_test.ts @@ -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; diff --git a/ts/test-mock/messaging/stories_test.ts b/ts/test-mock/messaging/stories_test.ts index 660462606c..ccbab6c46d 100644 --- a/ts/test-mock/messaging/stories_test.ts +++ b/ts/test-mock/messaging/stories_test.ts @@ -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; diff --git a/ts/test-mock/messaging/unknown_contact_test.ts b/ts/test-mock/messaging/unknown_contact_test.ts index 976a3e1ac6..b8c39a6b9e 100644 --- a/ts/test-mock/messaging/unknown_contact_test.ts +++ b/ts/test-mock/messaging/unknown_contact_test.ts @@ -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; diff --git a/ts/test-mock/playwright.ts b/ts/test-mock/playwright.ts index b97f62697c..b130b82362 100644 --- a/ts/test-mock/playwright.ts +++ b/ts/test-mock/playwright.ts @@ -81,6 +81,10 @@ export class App extends EventEmitter { return this.waitForEvent('provisioning-url'); } + public async waitForDbInitialized(): Promise { + return this.waitForEvent('db-initialized'); + } + public async waitUntilLoaded(): Promise { return this.waitForEvent('app-loaded'); } diff --git a/ts/test-mock/pnp/accept_gv2_invite_test.ts b/ts/test-mock/pnp/accept_gv2_invite_test.ts index a80609ba43..95d75e84b4 100644 --- a/ts/test-mock/pnp/accept_gv2_invite_test.ts +++ b/ts/test-mock/pnp/accept_gv2_invite_test.ts @@ -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; diff --git a/ts/test-mock/pnp/change_number_test.ts b/ts/test-mock/pnp/change_number_test.ts index 8c8c8bdf46..546b968784 100644 --- a/ts/test-mock/pnp/change_number_test.ts +++ b/ts/test-mock/pnp/change_number_test.ts @@ -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; diff --git a/ts/test-mock/pnp/merge_test.ts b/ts/test-mock/pnp/merge_test.ts index a73c630477..265b2ebca1 100644 --- a/ts/test-mock/pnp/merge_test.ts +++ b/ts/test-mock/pnp/merge_test.ts @@ -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; diff --git a/ts/test-mock/pnp/phone_discovery_test.ts b/ts/test-mock/pnp/phone_discovery_test.ts index bfe72514a7..fe8d527d33 100644 --- a/ts/test-mock/pnp/phone_discovery_test.ts +++ b/ts/test-mock/pnp/phone_discovery_test.ts @@ -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; diff --git a/ts/test-mock/pnp/pni_change_test.ts b/ts/test-mock/pnp/pni_change_test.ts index 266038c0fc..34328b1f2a 100644 --- a/ts/test-mock/pnp/pni_change_test.ts +++ b/ts/test-mock/pnp/pni_change_test.ts @@ -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; diff --git a/ts/test-mock/pnp/pni_signature_test.ts b/ts/test-mock/pnp/pni_signature_test.ts index c91d9458d1..6b22edc71d 100644 --- a/ts/test-mock/pnp/pni_signature_test.ts +++ b/ts/test-mock/pnp/pni_signature_test.ts @@ -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; diff --git a/ts/test-mock/pnp/pni_unlink_test.ts b/ts/test-mock/pnp/pni_unlink_test.ts index dd92249dd6..7e44eb6b19 100644 --- a/ts/test-mock/pnp/pni_unlink_test.ts +++ b/ts/test-mock/pnp/pni_unlink_test.ts @@ -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; diff --git a/ts/test-mock/pnp/send_gv2_invite_test.ts b/ts/test-mock/pnp/send_gv2_invite_test.ts index 01cca4a5fe..f9f13708b8 100644 --- a/ts/test-mock/pnp/send_gv2_invite_test.ts +++ b/ts/test-mock/pnp/send_gv2_invite_test.ts @@ -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; diff --git a/ts/test-mock/pnp/username_test.ts b/ts/test-mock/pnp/username_test.ts index e9707c105d..0713bfd3eb 100644 --- a/ts/test-mock/pnp/username_test.ts +++ b/ts/test-mock/pnp/username_test.ts @@ -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; diff --git a/ts/test-mock/rate-limit/story_test.ts b/ts/test-mock/rate-limit/story_test.ts index 456da0f12f..5d62ebd705 100644 --- a/ts/test-mock/rate-limit/story_test.ts +++ b/ts/test-mock/rate-limit/story_test.ts @@ -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; diff --git a/ts/test-mock/rate-limit/viewed_test.ts b/ts/test-mock/rate-limit/viewed_test.ts index 6e5af5e0d0..0575ced139 100644 --- a/ts/test-mock/rate-limit/viewed_test.ts +++ b/ts/test-mock/rate-limit/viewed_test.ts @@ -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; diff --git a/ts/test-mock/storage/archive_test.ts b/ts/test-mock/storage/archive_test.ts index f2e0631c3a..8c1bc1da59 100644 --- a/ts/test-mock/storage/archive_test.ts +++ b/ts/test-mock/storage/archive_test.ts @@ -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; diff --git a/ts/test-mock/storage/drop_test.ts b/ts/test-mock/storage/drop_test.ts index 89836791d7..ddca28310d 100644 --- a/ts/test-mock/storage/drop_test.ts +++ b/ts/test-mock/storage/drop_test.ts @@ -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; diff --git a/ts/test-mock/storage/max_read_keys_test.ts b/ts/test-mock/storage/max_read_keys_test.ts index a6dbe67bf2..57242e1b6f 100644 --- a/ts/test-mock/storage/max_read_keys_test.ts +++ b/ts/test-mock/storage/max_read_keys_test.ts @@ -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; diff --git a/ts/test-mock/storage/message_request_test.ts b/ts/test-mock/storage/message_request_test.ts index 3af91267f4..0f5dd28572 100644 --- a/ts/test-mock/storage/message_request_test.ts +++ b/ts/test-mock/storage/message_request_test.ts @@ -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; diff --git a/ts/test-mock/storage/pin_unpin_test.ts b/ts/test-mock/storage/pin_unpin_test.ts index 02af2c441c..1bc8bf6382 100644 --- a/ts/test-mock/storage/pin_unpin_test.ts +++ b/ts/test-mock/storage/pin_unpin_test.ts @@ -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; diff --git a/ts/test-mock/storage/sticker_test.ts b/ts/test-mock/storage/sticker_test.ts index 34f76a104d..e873c78f59 100644 --- a/ts/test-mock/storage/sticker_test.ts +++ b/ts/test-mock/storage/sticker_test.ts @@ -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;