diff --git a/lib/consts.ts b/lib/consts.ts index e092b73..b1cad50 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 DATASET_SYNC_DELAY_MS = 20 * 1000; // 20 seconds diff --git a/lib/lib.ts b/lib/lib.ts index c4590b7..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_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,6 +61,7 @@ export const testActor = ( ...DEFAULT_TEST_ACTOR_OPTIONS, ...testOptions, }; + const name = `${actorName}: ${testName}`; const shouldRun = !!RUN_ALL_PLATFORM_TESTS || config.has(actorName); vitestTest.runIf(shouldRun)(name, options, async (context: TYPE) => { @@ -280,8 +281,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(DATASET_SYNC_DELAY_MS); return new RunTestResult(apifyClient, run); };