Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,6 +61,7 @@ export const testActor = <T>(
...DEFAULT_TEST_ACTOR_OPTIONS,
...testOptions,
};

const name = `${actorName}: ${testName}`;
const shouldRun = !!RUN_ALL_PLATFORM_TESTS || config.has(actorName);
vitestTest.runIf(shouldRun)(name, options, async <TYPE extends TestContext>(context: TYPE) => {
Expand Down Expand Up @@ -280,8 +281,8 @@ const createStartRunFn = <T>(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);
};
Expand Down
Loading