Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Yury Semikhatskya4e90f20dc42
diff --git a/packages/playwright-test/src/runner/dispatcher.ts b/packages/playwright-test/src/runner/dispatcher.ts
index 3b4f39c6e6..e76b7581a2 100644
--- a/packages/playwright-test/src/runner/dispatcher.ts
+++ b/packages/playwright-test/src/runner/dispatcher.ts
@@ -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);
diff --git a/tests/playwright-test/runner.spec.ts b/tests/playwright-test/runner.spec.ts
index ce93a2e42b..8fcec7630b 100644
--- a/tests/playwright-test/runner.spec.ts
+++ b/tests/playwright-test/runner.spec.ts
@@ -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');
+});