Skip to content

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

test: retry one test runner test (#38298)

Dmitry Gozman98eec6690391
diff --git a/packages/playwright/src/runner/processHost.ts b/packages/playwright/src/runner/processHost.ts
index 06882a4d1b..7910bfe50f 100644
--- a/packages/playwright/src/runner/processHost.ts
+++ b/packages/playwright/src/runner/processHost.ts
@@ -51,6 +51,9 @@ export class ProcessHost extends EventEmitter {
async startRunner(runnerParams: any, options: { onStdOut?: (chunk: Buffer | string) => void, onStdErr?: (chunk: Buffer | string) => void } = {}): Promise<ProcessExitData | undefined> {
assert(!this.process, 'Internal error: starting the same process twice');
this.process = child_process.fork(require.resolve('../common/process'), {
+ // Note: we pass detached:false, so that workers are in the same process group.
+ // This way Ctrl+C or a kill command can shutdown all workers in case they misbehave.
+ // Otherwise user can end up with a bunch of workers stuck in a busy loop without self-destructing.
detached: false,
env: {
...process.env,
diff --git a/tests/playwright-test/runner.spec.ts b/tests/playwright-test/runner.spec.ts
index 89bd084db4..ef90b2ae13 100644
--- a/tests/playwright-test/runner.spec.ts
+++ b/tests/playwright-test/runner.spec.ts
@@ -115,43 +115,50 @@ test('should report subprocess creation error', async ({ runInlineTest }, testIn
expect(result.output).toContain('Error: worker process exited unexpectedly (code=42, signal=null)');
});
-test('should ignore subprocess creation error because of SIGINT', async ({ interactWithTestRunner }, testInfo) => {
- test.skip(process.platform === 'win32', 'No sending SIGINT on Windows');
-
- const readyFile = testInfo.outputPath('ready.txt');
- const testProcess = await interactWithTestRunner({
- 'hang.js': `
- require('fs').writeFileSync(${JSON.stringify(readyFile)}, 'ready');
- setInterval(() => {}, 1000);
- `,
- 'preload.js': `
- require('child_process').spawnSync(
- process.argv[0],
- [require('path').resolve('./hang.js')],
- { env: { ...process.env, NODE_OPTIONS: '' } },
- );
- `,
- 'a.spec.js': `
- import { test, expect } from '@playwright/test';
- test('fails', () => {});
- test('skipped', () => {});
- // Infect subprocesses to immediately hang when spawning a worker.
- process.env.NODE_OPTIONS = '--require ${JSON.stringify(testInfo.outputPath('preload.js'))}';
- `
- });
+test.describe(() => {
+ // Since we create worker processes in the same process group, SIGINT is issued concurrently to
+ // all processes. Therefore, we might end up with a dead worker before the runner starts to shutdown.
+ // This in turn leads to the "worker process exited unexpectedly" error. Retries should help.
+ test.describe.configure({ retries: 2 });
+
+ test('should ignore subprocess creation error because of SIGINT', async ({ interactWithTestRunner }, testInfo) => {
+ test.skip(process.platform === 'win32', 'No sending SIGINT on Windows');
+
+ const readyFile = testInfo.outputPath('ready.txt');
+ const testProcess = await interactWithTestRunner({
+ 'hang.js': `
+ require('fs').writeFileSync(${JSON.stringify(readyFile)}, 'ready');
+ setInterval(() => {}, 1000);
+ `,
+ 'preload.js': `
+ require('child_process').spawnSync(
+ process.argv[0],
+ [require('path').resolve('./hang.js')],
+ { env: { ...process.env, NODE_OPTIONS: '' } },
+ );
+ `,
+ 'a.spec.js': `
+ import { test, expect } from '@playwright/test';
+ test('fails', () => {});
+ test('skipped', () => {});
+ // Infect subprocesses to immediately hang when spawning a worker.
+ process.env.NODE_OPTIONS = '--require ${JSON.stringify(testInfo.outputPath('preload.js'))}';
+ `
+ });
- while (!fs.existsSync(readyFile))
- await new Promise(f => setTimeout(f, 100));
- process.kill(-testProcess.process.pid!, 'SIGINT');
+ while (!fs.existsSync(readyFile))
+ await new Promise(f => setTimeout(f, 100));
+ process.kill(-testProcess.process.pid!, 'SIGINT');
- const { exitCode } = await testProcess.exited;
- expect.soft(exitCode).toBe(130);
+ const { exitCode } = await testProcess.exited;
+ expect.soft(exitCode).toBe(130);
- const result = parseTestRunnerOutput(testProcess.output);
- expect.soft(result.passed).toBe(0);
- expect.soft(result.failed).toBe(0);
- expect.soft(result.didNotRun).toBe(2);
- expect.soft(result.output).not.toContain('worker process exited unexpectedly');
+ const result = parseTestRunnerOutput(testProcess.output);
+ expect.soft(result.passed).toBe(0);
+ expect.soft(result.failed).toBe(0);
+ expect.soft(result.didNotRun).toBe(2);
+ expect.soft(result.output).not.toContain('worker process exited unexpectedly');
+ });
});
test('sigint should stop workers', async ({ interactWithTestRunner }) => {