fix(runner): do not hang on worker exit before tests (#22742)

This commit is contained in:
Yury Semikhatsky 2023-05-01 14:54:48 -07:00 committed by GitHub
parent fcd966c4e5
commit a4e90f20dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -214,8 +214,10 @@ export class Dispatcher {
const remainingByTestId = new Map(testGroup.tests.map(e => [e.id, e]));
const failedTestIds = new Set<string>();
let runningTest = false;
const onTestBegin = (params: TestBeginPayload) => {
runningTest = true;
const data = this._testById.get(params.testId)!;
const result = data.test._appendTestResult();
data.resultByWorkerIndex.set(worker.workerIndex, { result, steps: new Map() });
@ -228,6 +230,7 @@ export class Dispatcher {
worker.addListener('testBegin', onTestBegin);
const onTestEnd = (params: TestEndPayload) => {
runningTest = false;
remainingByTestId.delete(params.testId);
if (this._hasReachedMaxFailures()) {
// Do not show more than one error to avoid confusion, but report
@ -339,7 +342,7 @@ export class Dispatcher {
if (runData) {
result = runData.result;
} else {
if (onlyStartedTests)
if (onlyStartedTests && runningTest)
return true;
result = data.test._appendTestResult();
this._reporter.onTestBegin(test, result);

View File

@ -526,3 +526,19 @@ throw new Error('should not load nomap.spec.js');`,
expect(result.output).not.toContain('should not load');
expect(result.output).toContain('gherkin.feature:1');
});
test('should not hang on worker error in test file', async ({ runInlineTest }) => {
const result = await runInlineTest({
'example.spec.js': `
import { test, expect } from '@playwright/test';
if (process.env.TEST_WORKER_INDEX)
process.exit(1);
test('test 1', async () => {});
test('test 2', async () => {});
`,
}, { 'timeout': 3000 });
expect(result.exitCode).toBe(1);
expect(result.results[0].status).toBe('failed');
expect(result.results[0].error.message).toContain('Internal error: worker process exited unexpectedly');
expect(result.results[1].status).toBe('skipped');
});