Skip to content

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

test: report and kill child processes which are leaking after test (#22237)

Max Schmitt2df0f0738d0c
diff --git a/tests/config/commonFixtures.ts b/tests/config/commonFixtures.ts
index edd464465b..e9c4932b1e 100644
--- a/tests/config/commonFixtures.ts
+++ b/tests/config/commonFixtures.ts
@@ -87,19 +87,19 @@ export class TestChildProcess {
}
async close() {
- if (!this.process.killed)
+ if (this.process.kill(0))
this._killProcessGroup('SIGINT');
return this.exited;
}
async kill() {
- if (!this.process.killed)
+ if (this.process.kill(0))
this._killProcessGroup('SIGKILL');
return this.exited;
}
private _killProcessGroup(signal: 'SIGINT' | 'SIGKILL') {
- if (!this.process.pid || this.process.killed)
+ if (!this.process.pid || !this.process.kill(0))
return;
try {
if (process.platform === 'win32')
@@ -150,7 +150,16 @@ export const commonFixtures: Fixtures<CommonFixtures, CommonWorkerFixtures> = {
processes.push(process);
return process;
});
- await Promise.all(processes.map(child => child.close()));
+ await Promise.all(processes.map(async child => {
+ await Promise.race([
+ child.exited,
+ new Promise(f => setTimeout(f, 3_000)),
+ ]);
+ if (child.process.kill(0)) {
+ await child.kill();
+ throw new Error(`Process ${child.params.command.join(' ')} is still running. Leaking process?\nOutput:${child.output}`);
+ }
+ }));
if (testInfo.status !== 'passed' && testInfo.status !== 'skipped' && !process.env.PWTEST_DEBUG) {
for (const process of processes) {
console.log('====== ' + process.params.command.join(' '));
diff --git a/tests/library/inspector/inspectorTest.ts b/tests/library/inspector/inspectorTest.ts
index 0b12686468..30e1c65432 100644
--- a/tests/library/inspector/inspectorTest.ts
+++ b/tests/library/inspector/inspectorTest.ts
@@ -73,8 +73,8 @@ export const test = contextTest.extend<CLITestArgs>({
cli = new CLIMock(childProcess, browserName, channel, headless, cliArgs, launchOptions.executablePath, noAutoExit);
return cli;
});
- if (cli)
- await cli.exited.catch(() => {});
+ // Discard any exit error and let childProcess fixture report leaking processes (processwes which do not exit).
+ cli?.exited.catch(() => {});
},
openRecorder: async ({ page, recorderPageGetter }, run) => {