From afbd8d615a1e577146de7753a0385b030af51d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20H=C3=BCgel?= Date: Wed, 12 Aug 2026 15:54:34 +0200 Subject: [PATCH 1/2] Fix flaky runtime sync test waits --- packages/runtime/test/lib/testUtils.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/runtime/test/lib/testUtils.ts b/packages/runtime/test/lib/testUtils.ts index 201e64e80..664cf3bec 100644 --- a/packages/runtime/test/lib/testUtils.ts +++ b/packages/runtime/test/lib/testUtils.ts @@ -67,13 +67,17 @@ import { import { TestRuntimeServices } from "./RuntimeServiceProvider"; import { TestNotificationItem } from "./TestNotificationItem"; +const DEFAULT_SYNC_UNTIL_TIMEOUT = 10000; +const MAX_SYNC_UNTIL_SLEEP = 250; + export async function syncUntil(transportServices: TransportServices, until: (syncResult: SyncEverythingResponse) => boolean): Promise { const finalSyncResult: SyncEverythingResponse = { messages: [], relationships: [], identityDeletionProcesses: [], files: [] }; let iterationNumber = 0; let criteriaMet: boolean; + const startedAt = Date.now(); do { - await sleep(iterationNumber * 25); + await sleep(Math.min(iterationNumber * 25, MAX_SYNC_UNTIL_SLEEP)); const currentIterationSyncResult = (await transportServices.account.syncEverything()).value; @@ -84,8 +88,8 @@ export async function syncUntil(transportServices: TransportServices, until: (sy iterationNumber++; criteriaMet = until(finalSyncResult); - } while (!criteriaMet && iterationNumber < 15); - if (!criteriaMet) throw new Error("syncUntil timed out."); + } while (!criteriaMet && Date.now() - startedAt < DEFAULT_SYNC_UNTIL_TIMEOUT); + if (!criteriaMet) throw new Error(`syncUntil timed out after ${DEFAULT_SYNC_UNTIL_TIMEOUT}ms.`); return finalSyncResult; } @@ -151,8 +155,9 @@ export async function syncUntilHasEvent( ): Promise { let iterationNumber = 0; let event: Event | undefined; + const startedAt = Date.now(); do { - await sleep(iterationNumber * 25); + await sleep(Math.min(iterationNumber * 25, MAX_SYNC_UNTIL_SLEEP)); await runtimeServices.transport.account.syncEverything(); event = runtimeServices.eventBus.publishedEvents.find( @@ -163,8 +168,8 @@ export async function syncUntilHasEvent( ); iterationNumber++; - } while (!event && iterationNumber < 15); - if (!event) throw new Error("syncUntil timed out."); + } while (!event && Date.now() - startedAt < DEFAULT_SYNC_UNTIL_TIMEOUT); + if (!event) throw new Error(`syncUntil timed out after ${DEFAULT_SYNC_UNTIL_TIMEOUT}ms.`); return event; } From 8bb5b849864f39aea825a4d6146bff9eb0bc0b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20H=C3=BCgel?= Date: Wed, 12 Aug 2026 16:07:48 +0200 Subject: [PATCH 2/2] Fix flaky transport sync test waits --- packages/transport/test/testHelpers/TestUtil.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/transport/test/testHelpers/TestUtil.ts b/packages/transport/test/testHelpers/TestUtil.ts index 93d76642f..8e657413b 100644 --- a/packages/transport/test/testHelpers/TestUtil.ts +++ b/packages/transport/test/testHelpers/TestUtil.ts @@ -34,6 +34,9 @@ import { } from "../../src"; export class TestUtil { + private static readonly DEFAULT_SYNC_UNTIL_TIMEOUT = 60000; + private static readonly MAX_SYNC_UNTIL_SLEEP = 1000; + public static loggerFactory = new NodeLoggerFactory({ appenders: { consoleAppender: { @@ -466,18 +469,21 @@ export class TestUtil { const syncResult = new ChangedItems(); let iterationNumber = 0; + let criteriaMet = false; + const startedAt = Date.now(); do { - await sleep(150 * iterationNumber); + await sleep(Math.min(150 * iterationNumber, TestUtil.MAX_SYNC_UNTIL_SLEEP)); const newSyncResult = await accountController.syncEverything(); syncResult.messages.push(...newSyncResult.messages); syncResult.relationships.push(...newSyncResult.relationships); syncResult.identityDeletionProcesses.push(...newSyncResult.identityDeletionProcesses); syncResult.files.push(...newSyncResult.files); iterationNumber++; - } while (!until(syncResult) && iterationNumber < 20); + criteriaMet = until(syncResult); + } while (!criteriaMet && Date.now() - startedAt < TestUtil.DEFAULT_SYNC_UNTIL_TIMEOUT); - if (!until(syncResult)) { - throw new Error("syncUntil condition was not met"); + if (!criteriaMet) { + throw new Error(`syncUntil condition was not met after ${TestUtil.DEFAULT_SYNC_UNTIL_TIMEOUT}ms`); } return syncResult; }