Skip to content

Commit

Permalink
FI-1432 fix: Playwright timeout for test with waitBeforeRetry
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Nov 11, 2024
1 parent da61cba commit a3276ca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/types/testRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type TestUnit = Readonly<{
outputDirectoryName: string;
retryIndex: number;
runId: RunId;
startTimeInMs: UtcTimeInMs;
testController: PlaywrightTestArgs;
testFn: TestFn;
testStaticOptions: TestStaticOptions;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/test/beforeTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const additionToPlaywrightTestTimeout = 500;
* @internal
*/
export const beforeTest = ({
beforeRetryTimeout,
outputDirectoryName,
retryIndex,
runId,
startTimeInMs,
testFn,
testStaticOptions,
}: TestUnit): void => {
Expand All @@ -47,7 +47,7 @@ export const beforeTest = ({
const testIdleTimeout = options.testIdleTimeout ?? testIdleTimeoutFromConfig;
const testTimeout = options.testTimeout ?? testTimeoutFromConfig;

test.setTimeout(testTimeout + additionToPlaywrightTestTimeout + (beforeRetryTimeout ?? 0));
test.setTimeout(testTimeout + additionToPlaywrightTestTimeout + (Date.now() - startTimeInMs));

setTestIdleTimeout(testIdleTimeout);
setTestTimeout(testTimeout);
Expand Down
17 changes: 7 additions & 10 deletions src/utils/test/getRunTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {preparePage} from './preparePage';
import {runTestFn} from './runTestFn';
import {waitBeforeRetry} from './waitBeforeRetry';

import type {RunTest, Test, TestStaticOptions, TestUnit} from '../../types/internal';
import type {RunTest, Test, TestStaticOptions, TestUnit, UtcTimeInMs} from '../../types/internal';

/**
* Get complete run test function by the complete test options.
Expand All @@ -23,6 +23,7 @@ export const getRunTest =
(test: Test): RunTest =>
({context, page, request}, testInfo): Promise<void> => {
const runTest = async (): Promise<void> => {
const startTimeInMs = Date.now() as UtcTimeInMs;
const retryIndex = testInfo.retry + 1;
const runId = createRunId(test, retryIndex);

Expand All @@ -34,29 +35,25 @@ export const getRunTest =

try {
testStaticOptions = getTestStaticOptions(test, testInfo);

shouldRunTest = await getShouldRunTest(testStaticOptions);

if (!shouldRunTest) {
return;
}

const beforeRetryTimeout = await waitBeforeRetry(runId, testStaticOptions);

clearPage = await preparePage(page);

const testController = {context, page, request};

const testUnit: TestUnit = {
beforeRetryTimeout,
beforeRetryTimeout: await waitBeforeRetry(runId, testStaticOptions),
outputDirectoryName: getOutputDirectoryName(testInfo.outputDir),
retryIndex,
runId,
testController,
startTimeInMs,
testController: {context, page, request},
testFn: test.testFn,
testStaticOptions,
};

clearPage = await preparePage(page);

beforeTest(testUnit);

await runTestFn(testUnit);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/test/waitBeforeRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {FullTestRun, RunId, TestStaticOptions} from '../../types/internal';

import {test} from '@playwright/test';

const additionToTimeout = 500;
const additionToTimeout = 10_000;

/**
* Waits before running test for some time from pack config (for retries).
Expand Down

0 comments on commit a3276ca

Please sign in to comment.