From 9c961860819796e9dc51d34dcdf17e383e10acf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pr=C5=AF=C5=A1a?= <87543374+Patai5@users.noreply.github.com> Date: Tue, 4 Aug 2026 23:14:17 +0200 Subject: [PATCH 1/2] fix: increase default dataset sync timeout --- lib/consts.ts | 7 +++++++ lib/lib.ts | 17 ++++++++++++----- lib/types.ts | 7 +++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/consts.ts b/lib/consts.ts index e092b73..910fe96 100644 --- a/lib/consts.ts +++ b/lib/consts.ts @@ -16,3 +16,10 @@ export const TO_FINISH_WITH_OPTIONS: ToFinishWithOptionsWithDefaults = { * Both the test runs and the vitest test specs should finish in this time - 1 hour */ export const DEFAULT_TEST_RUN_DURATION_MS = 60 * 60 * 1000; // 1 hour + +/** + * Delay before checking the dataset and statistics after a run finishes to resolve eventual consistency. + * - This value should ensure that the dataset and statistics are fully updated before any assertions are made. + * - Super rarely the platform is still not synced even after 10s, so 20s should be sufficient practically always. + */ +export const DEFAULT_DATASET_SYNC_DELAY_MS = 20 * 1000; // 20 seconds diff --git a/lib/lib.ts b/lib/lib.ts index c4590b7..4663314 100644 --- a/lib/lib.ts +++ b/lib/lib.ts @@ -3,7 +3,7 @@ import { ApifyClient } from 'apify-client'; import type { SuiteFactory, TestContext, TestFunction } from 'vitest'; import { describe as vitestDescribe, ExpectStatic, test as vitestTest } from 'vitest'; -import { DEFAULT_TEST_RUN_DURATION_MS } from './consts.js'; +import { DEFAULT_DATASET_SYNC_DELAY_MS, DEFAULT_TEST_RUN_DURATION_MS } from './consts.js'; import { extendExpect } from './extend-expect.js'; import { RunTestResult } from './run-test-result.js'; import type { ActorBuild, ActorTestOptions, RunOptions } from './types.js'; @@ -61,13 +61,15 @@ export const testActor = ( ...DEFAULT_TEST_ACTOR_OPTIONS, ...testOptions, }; + const { datasetSyncDelayMs = DEFAULT_DATASET_SYNC_DELAY_MS } = options; + const name = `${actorName}: ${testName}`; const shouldRun = !!RUN_ALL_PLATFORM_TESTS || config.has(actorName); vitestTest.runIf(shouldRun)(name, options, async (context: TYPE) => { const { expect, ...rest } = context; await fn({ expect: extendExpect(expect), - run: createStartRunFn(actorName, context), + run: createStartRunFn(actorName, context, { datasetSyncDelayMs }), ...rest, }); }); @@ -247,7 +249,12 @@ const createStandbyTask = async (actorNameOrId: string, buildNumber?: string): P } }; -const createStartRunFn = (actorNameOrId: string, testContext: TestContext) => { +const createStartRunFn = ( + actorNameOrId: string, + testContext: TestContext, + testOptions: { datasetSyncDelayMs: number }, +) => { + const { datasetSyncDelayMs } = testOptions; const { annotate, task } = testContext; const actorConfig = config.get(actorNameOrId); const build = actorConfig?.buildNumber; @@ -280,8 +287,8 @@ const createStartRunFn = (actorNameOrId: string, testContext: TestContext) => actorName: actorNameOrId, }; - // waiting for datasetItemCount and chargedEventCounts to sync - await sleep(10_000); + // waiting for dataset and statistics to sync, the Apify platform is only eventually consistent. + await sleep(datasetSyncDelayMs); return new RunTestResult(apifyClient, run); }; diff --git a/lib/types.ts b/lib/types.ts index 6b301f3..be77f2f 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -144,6 +144,13 @@ export type ActorTestOptions = Omit & { * @default 60 * 60 * 1000 // 1 hour */ timeout?: ActorCallOptions['timeout']; + /** + * Delay in milliseconds before checking the dataset and statistics after a run finishes. + * - Useful for ensuring that the dataset is fully synchronized, the Apify platform is only eventually consistent. + * + * @default 20_000 // 20 seconds + */ + datasetSyncDelayMs?: number; }; declare module 'vitest' { From a721cb366cb69bf2d3730a19479b548ea3b2273e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pr=C5=AF=C5=A1a?= <87543374+Patai5@users.noreply.github.com> Date: Thu, 6 Aug 2026 12:57:05 +0200 Subject: [PATCH 2/2] fix: remove unnecessary dataset sync delay ms option --- lib/consts.ts | 2 +- lib/lib.ts | 14 ++++---------- lib/types.ts | 7 ------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/consts.ts b/lib/consts.ts index 910fe96..b1cad50 100644 --- a/lib/consts.ts +++ b/lib/consts.ts @@ -22,4 +22,4 @@ export const DEFAULT_TEST_RUN_DURATION_MS = 60 * 60 * 1000; // 1 hour * - This value should ensure that the dataset and statistics are fully updated before any assertions are made. * - Super rarely the platform is still not synced even after 10s, so 20s should be sufficient practically always. */ -export const DEFAULT_DATASET_SYNC_DELAY_MS = 20 * 1000; // 20 seconds +export const DATASET_SYNC_DELAY_MS = 20 * 1000; // 20 seconds diff --git a/lib/lib.ts b/lib/lib.ts index 4663314..96bdad3 100644 --- a/lib/lib.ts +++ b/lib/lib.ts @@ -3,7 +3,7 @@ import { ApifyClient } from 'apify-client'; import type { SuiteFactory, TestContext, TestFunction } from 'vitest'; import { describe as vitestDescribe, ExpectStatic, test as vitestTest } from 'vitest'; -import { DEFAULT_DATASET_SYNC_DELAY_MS, DEFAULT_TEST_RUN_DURATION_MS } from './consts.js'; +import { DATASET_SYNC_DELAY_MS, DEFAULT_TEST_RUN_DURATION_MS } from './consts.js'; import { extendExpect } from './extend-expect.js'; import { RunTestResult } from './run-test-result.js'; import type { ActorBuild, ActorTestOptions, RunOptions } from './types.js'; @@ -61,7 +61,6 @@ export const testActor = ( ...DEFAULT_TEST_ACTOR_OPTIONS, ...testOptions, }; - const { datasetSyncDelayMs = DEFAULT_DATASET_SYNC_DELAY_MS } = options; const name = `${actorName}: ${testName}`; const shouldRun = !!RUN_ALL_PLATFORM_TESTS || config.has(actorName); @@ -69,7 +68,7 @@ export const testActor = ( const { expect, ...rest } = context; await fn({ expect: extendExpect(expect), - run: createStartRunFn(actorName, context, { datasetSyncDelayMs }), + run: createStartRunFn(actorName, context), ...rest, }); }); @@ -249,12 +248,7 @@ const createStandbyTask = async (actorNameOrId: string, buildNumber?: string): P } }; -const createStartRunFn = ( - actorNameOrId: string, - testContext: TestContext, - testOptions: { datasetSyncDelayMs: number }, -) => { - const { datasetSyncDelayMs } = testOptions; +const createStartRunFn = (actorNameOrId: string, testContext: TestContext) => { const { annotate, task } = testContext; const actorConfig = config.get(actorNameOrId); const build = actorConfig?.buildNumber; @@ -288,7 +282,7 @@ const createStartRunFn = ( }; // waiting for dataset and statistics to sync, the Apify platform is only eventually consistent. - await sleep(datasetSyncDelayMs); + await sleep(DATASET_SYNC_DELAY_MS); return new RunTestResult(apifyClient, run); }; diff --git a/lib/types.ts b/lib/types.ts index be77f2f..6b301f3 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -144,13 +144,6 @@ export type ActorTestOptions = Omit & { * @default 60 * 60 * 1000 // 1 hour */ timeout?: ActorCallOptions['timeout']; - /** - * Delay in milliseconds before checking the dataset and statistics after a run finishes. - * - Useful for ensuring that the dataset is fully synchronized, the Apify platform is only eventually consistent. - * - * @default 20_000 // 20 seconds - */ - datasetSyncDelayMs?: number; }; declare module 'vitest' {