Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added NON_ISOLATED_TESTS env for getting round test isolation if needed #32753

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion packages/playwright/src/runner/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class JobDispatcher {
// - there are no remaining
// - we are here not because something failed
// - no unrecoverable worker error
if (!this._remainingByTestId.size && !this._failedTests.size && !params.fatalErrors.length && !params.skipTestsDueToSetupFailure.length && !params.fatalUnknownTestIds && !params.unexpectedExitError) {
if (!this._remainingByTestId.size && !this._failedTests.size && !params.fatalErrors.length && !params.skipTestsDueToSetupFailure.length && !params.fatalUnknownTestIds && !params.unexpectedExitError && !process.env.NON_ISOLATED_TESTS) {
this._finished({ didFail: false });
return;
}
Expand Down
30 changes: 29 additions & 1 deletion packages/playwright/src/runner/testGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function createTestGroups(projectSuite: Suite, workers: number): TestGrou
// These should run as a serial group, each group is independent, key === serial suite.
parallel: Map<Suite | TestCase, TestGroup>,
parallelWithHooks: TestGroup,
parallelDescribes: Map<string, Array<TestCase>>,
}>>();

const createGroup = (test: TestCase): TestGroup => {
Expand All @@ -73,6 +74,7 @@ export function createTestGroups(projectSuite: Suite, workers: number): TestGrou
general: createGroup(test),
parallel: new Map(),
parallelWithHooks: createGroup(test),
parallelDescribes: new Map(),
};
withWorkerHash.set(test._requireFile, withRequireFile);
}
Expand All @@ -81,16 +83,28 @@ export function createTestGroups(projectSuite: Suite, workers: number): TestGrou
let insideParallel = false;
let outerMostSequentialSuite: Suite | undefined;
let hasAllHooks = false;
let hasDescribe = false;
let currentTitle = '';
for (let parent: Suite | undefined = test.parent; parent; parent = parent.parent) {
if (parent._parallelMode === 'serial' || parent._parallelMode === 'default')
outerMostSequentialSuite = parent;
insideParallel = insideParallel || parent._parallelMode === 'parallel';
hasAllHooks = hasAllHooks || parent._hooks.some(hook => hook.type === 'beforeAll' || hook.type === 'afterAll');
hasDescribe = hasDescribe || parent.type === 'describe';
if (parent._type === 'describe')
currentTitle = parent.title;
}

if (insideParallel) {
if (hasAllHooks && !outerMostSequentialSuite) {
if ((hasAllHooks && !outerMostSequentialSuite && !process.env.NON_ISOLATED_TESTS) || (!hasDescribe && process.env.NON_ISOLATED_TESTS)) {
withRequireFile.parallelWithHooks.tests.push(test);
} else if (hasDescribe && process.env.NON_ISOLATED_TESTS) {
if (!withRequireFile.parallelDescribes.get(currentTitle)) {
withRequireFile.parallelDescribes.set(currentTitle, [test]);
} else {
const value = withRequireFile.parallelDescribes.get(currentTitle);
value?.push(test);
}
} else {
const key = outerMostSequentialSuite || test;
let group = withRequireFile.parallel.get(key);
Expand Down Expand Up @@ -125,6 +139,20 @@ export function createTestGroups(projectSuite: Suite, workers: number): TestGrou
}
lastGroup.tests.push(test);
}
if (process.env.NON_ISOLATED_TESTS) {
const describeGroups = Array.from(withRequireFile.parallelDescribes, ([name, value]) => ({ name, value }));
let lastDescribeGroup;
for (const testGroup of describeGroups) {
lastDescribeGroup = null;
for (const test of testGroup.value) {
if (!lastDescribeGroup) {
lastDescribeGroup = createGroup(test);
result.push(lastDescribeGroup);
}
lastDescribeGroup.tests.push(test);
}
}
}
}
}
return result;
Expand Down
16 changes: 10 additions & 6 deletions packages/playwright/src/worker/workerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class WorkerMain extends ProcessRunner {
}
};

if (!this._isStopped)
if (!(this._isStopped && !process.env.NON_ISOLATED_TESTS))
this._fixtureRunner.setPool(test._pool!);

const suites = getSuites(test);
Expand Down Expand Up @@ -320,7 +320,7 @@ export class WorkerMain extends ProcessRunner {
await testInfo._tracing.startIfNeeded(traceFixtureRegistration.fn);
});

if (this._isStopped || isSkipped) {
if ((this._isStopped && !process.env.NON_ISOLATED_TESTS) || isSkipped) {
// Two reasons to get here:
// - Last test is skipped, so we should not run the test, but run the cleanup.
// - Worker is requested to stop, but was not able to run full cleanup yet.
Expand Down Expand Up @@ -396,7 +396,7 @@ export class WorkerMain extends ProcessRunner {
// In case of failure the worker will be stopped and we have to make sure that afterAll
// hooks run before worker fixtures teardown.
for (const suite of reversedSuites) {
if (!nextSuites.has(suite) || testInfo._isFailure()) {
if (!nextSuites.has(suite) || (testInfo._isFailure() && !process.env.NON_ISOLATED_TESTS)) {
try {
await this._runAfterAllHooksForSuite(suite, testInfo);
} catch (error) {
Expand All @@ -412,7 +412,7 @@ export class WorkerMain extends ProcessRunner {
if (testInfo._isFailure())
this._isStopped = true;

if (this._isStopped) {
if (this._isStopped && !process.env.NON_ISOLATED_TESTS) {
// Run all remaining "afterAll" hooks and teardown all fixtures when worker is shutting down.
// Mark as "cleaned up" early to avoid running cleanup twice.
this._didRunFullCleanup = true;
Expand Down Expand Up @@ -534,14 +534,18 @@ export class WorkerMain extends ProcessRunner {
}
}
}
if (firstError)
if (firstError) {
if (process.env.NON_ISOLATED_TESTS)
this._didRunFullCleanup = true;
throw firstError;
}
}

private async _runAfterAllHooksForSuite(suite: Suite, testInfo: TestInfoImpl) {
if (!this._activeSuites.has(suite))
return;
this._activeSuites.delete(suite);
if (!process.env.NON_ISOLATED_TESTS)
this._activeSuites.delete(suite);
await this._runAllHooksForSuite(suite, testInfo, 'afterAll');
}

Expand Down