fix(test runner): proper serial mode with beforeAll/afterAll failures (#9183)
This commit is contained in:
parent
37ff9db7a0
commit
fa536786f2
|
|
@ -126,7 +126,9 @@ export class Dispatcher {
|
||||||
worker.stop();
|
worker.stop();
|
||||||
worker.didFail = true;
|
worker.didFail = true;
|
||||||
|
|
||||||
const retryCandidates = new Set<string>();
|
const failedTestIds = new Set<string>();
|
||||||
|
if (params.failedTestId)
|
||||||
|
failedTestIds.add(params.failedTestId);
|
||||||
|
|
||||||
// In case of fatal error, report first remaining test as failing with this error,
|
// In case of fatal error, report first remaining test as failing with this error,
|
||||||
// and all others as skipped.
|
// and all others as skipped.
|
||||||
|
|
@ -142,7 +144,7 @@ export class Dispatcher {
|
||||||
result.error = params.fatalError;
|
result.error = params.fatalError;
|
||||||
result.status = first ? 'failed' : 'skipped';
|
result.status = first ? 'failed' : 'skipped';
|
||||||
this._reportTestEnd(test, result);
|
this._reportTestEnd(test, result);
|
||||||
retryCandidates.add(test._id);
|
failedTestIds.add(test._id);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
|
|
@ -156,40 +158,45 @@ export class Dispatcher {
|
||||||
remaining = [];
|
remaining = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.failedTestId) {
|
const retryCandidates = new Set<string>();
|
||||||
retryCandidates.add(params.failedTestId);
|
const serialSuitesWithFailures = new Set<Suite>();
|
||||||
|
|
||||||
|
for (const failedTestId of failedTestIds) {
|
||||||
|
retryCandidates.add(failedTestId);
|
||||||
|
|
||||||
let outermostSerialSuite: Suite | undefined;
|
let outermostSerialSuite: Suite | undefined;
|
||||||
for (let parent = this._testById.get(params.failedTestId)!.test.parent; parent; parent = parent.parent) {
|
for (let parent = this._testById.get(failedTestId)!.test.parent; parent; parent = parent.parent) {
|
||||||
if (parent._parallelMode === 'serial')
|
if (parent._parallelMode === 'serial')
|
||||||
outermostSerialSuite = parent;
|
outermostSerialSuite = parent;
|
||||||
}
|
}
|
||||||
|
if (outermostSerialSuite)
|
||||||
|
serialSuitesWithFailures.add(outermostSerialSuite);
|
||||||
|
}
|
||||||
|
|
||||||
if (outermostSerialSuite) {
|
// We have failed tests that belong to a serial suite.
|
||||||
// Failed test belongs to a serial suite. We should skip all future tests
|
// We should skip all future tests from the same serial suite.
|
||||||
// from the same serial suite.
|
remaining = remaining.filter(test => {
|
||||||
remaining = remaining.filter(test => {
|
let parent = test.parent;
|
||||||
let parent = test.parent;
|
while (parent && !serialSuitesWithFailures.has(parent))
|
||||||
while (parent && parent !== outermostSerialSuite)
|
parent = parent.parent;
|
||||||
parent = parent.parent;
|
|
||||||
|
|
||||||
// Does not belong to the same serial suite, keep it.
|
// Does not belong to the failed serial suite, keep it.
|
||||||
if (!parent)
|
if (!parent)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Emulate a "skipped" run, and drop this test from remaining.
|
// Emulate a "skipped" run, and drop this test from remaining.
|
||||||
const { result } = this._testById.get(test._id)!;
|
const { result } = this._testById.get(test._id)!;
|
||||||
this._reporter.onTestBegin?.(test, result);
|
this._reporter.onTestBegin?.(test, result);
|
||||||
result.status = 'skipped';
|
result.status = 'skipped';
|
||||||
this._reportTestEnd(test, result);
|
this._reportTestEnd(test, result);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add all tests from the same serial suite for possible retry.
|
for (const serialSuite of serialSuitesWithFailures) {
|
||||||
// These will only be retried together, because they have the same
|
// Add all tests from faiiled serial suites for possible retry.
|
||||||
// "retries" setting and the same number of previous runs.
|
// These will only be retried together, because they have the same
|
||||||
outermostSerialSuite.allTests().forEach(test => retryCandidates.add(test._id));
|
// "retries" setting and the same number of previous runs.
|
||||||
}
|
serialSuite.allTests().forEach(test => retryCandidates.add(test._id));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const testId of retryCandidates) {
|
for (const testId of retryCandidates) {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ import { DeadlineRunner, raceAgainstDeadline } from '../utils/async';
|
||||||
|
|
||||||
const removeFolderAsync = util.promisify(rimraf);
|
const removeFolderAsync = util.promisify(rimraf);
|
||||||
|
|
||||||
|
type TestData = { testId: string, testInfo: TestInfoImpl, type: 'test' | 'beforeAll' | 'afterAll' };
|
||||||
|
|
||||||
export class WorkerRunner extends EventEmitter {
|
export class WorkerRunner extends EventEmitter {
|
||||||
private _params: WorkerInitParams;
|
private _params: WorkerInitParams;
|
||||||
private _loader!: Loader;
|
private _loader!: Loader;
|
||||||
|
|
@ -47,7 +49,7 @@ export class WorkerRunner extends EventEmitter {
|
||||||
private _isStopped = false;
|
private _isStopped = false;
|
||||||
private _runFinished = Promise.resolve();
|
private _runFinished = Promise.resolve();
|
||||||
private _currentDeadlineRunner: DeadlineRunner<any> | undefined;
|
private _currentDeadlineRunner: DeadlineRunner<any> | undefined;
|
||||||
_currentTest: { testId: string, testInfo: TestInfoImpl, type: 'test' | 'beforeAll' | 'afterAll' } | null = null;
|
_currentTest: TestData | null = null;
|
||||||
|
|
||||||
constructor(params: WorkerInitParams) {
|
constructor(params: WorkerInitParams) {
|
||||||
super();
|
super();
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,78 @@ test('test.describe.serial should work with retry', async ({ runInlineTest }) =>
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test.describe.serial should work with retry and beforeAll failure', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.ts': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test.describe.serial('serial suite', () => {
|
||||||
|
test('test1', async ({}) => {
|
||||||
|
console.log('\\n%%test1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('inner suite', () => {
|
||||||
|
test.beforeAll(async ({}, testInfo) => {
|
||||||
|
console.log('\\n%%beforeAll');
|
||||||
|
expect(testInfo.retry).toBe(1);
|
||||||
|
});
|
||||||
|
test('test2', async ({}) => {
|
||||||
|
console.log('\\n%%test2');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { retries: 1 });
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(result.flaky).toBe(1);
|
||||||
|
expect(result.failed).toBe(0);
|
||||||
|
expect(result.skipped).toBe(0);
|
||||||
|
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||||||
|
'%%test1',
|
||||||
|
'%%beforeAll',
|
||||||
|
'%%test1',
|
||||||
|
'%%beforeAll',
|
||||||
|
'%%test2',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test.describe.serial should work with retry and afterAll failure', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.ts': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test.describe.serial('serial suite', () => {
|
||||||
|
test.describe('inner suite', () => {
|
||||||
|
let firstRun = false;
|
||||||
|
test('test1', async ({}, testInfo) => {
|
||||||
|
console.log('\\n%%test1');
|
||||||
|
firstRun = testInfo.retry === 0;
|
||||||
|
});
|
||||||
|
test.afterAll(async ({}, testInfo) => {
|
||||||
|
console.log('\\n%%afterAll');
|
||||||
|
expect(firstRun).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test2', async ({}) => {
|
||||||
|
console.log('\\n%%test2');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { retries: 1 });
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(result.flaky).toBe(1);
|
||||||
|
expect(result.failed).toBe(0);
|
||||||
|
expect(result.skipped).toBe(0);
|
||||||
|
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||||||
|
'%%test1',
|
||||||
|
'%%afterAll',
|
||||||
|
'%%test1',
|
||||||
|
'%%afterAll',
|
||||||
|
'%%test2',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('test.describe.serial.only should work', async ({ runInlineTest }) => {
|
test('test.describe.serial.only should work', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue