mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: report and kill child processes which are leaking after test (#22237)
This commit is contained in:
parent
44b63b042e
commit
2df0f0738d
@ -87,19 +87,19 @@ export class TestChildProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
if (!this.process.killed)
|
if (this.process.kill(0))
|
||||||
this._killProcessGroup('SIGINT');
|
this._killProcessGroup('SIGINT');
|
||||||
return this.exited;
|
return this.exited;
|
||||||
}
|
}
|
||||||
|
|
||||||
async kill() {
|
async kill() {
|
||||||
if (!this.process.killed)
|
if (this.process.kill(0))
|
||||||
this._killProcessGroup('SIGKILL');
|
this._killProcessGroup('SIGKILL');
|
||||||
return this.exited;
|
return this.exited;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _killProcessGroup(signal: 'SIGINT' | 'SIGKILL') {
|
private _killProcessGroup(signal: 'SIGINT' | 'SIGKILL') {
|
||||||
if (!this.process.pid || this.process.killed)
|
if (!this.process.pid || !this.process.kill(0))
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
if (process.platform === 'win32')
|
if (process.platform === 'win32')
|
||||||
@ -150,7 +150,16 @@ export const commonFixtures: Fixtures<CommonFixtures, CommonWorkerFixtures> = {
|
|||||||
processes.push(process);
|
processes.push(process);
|
||||||
return 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) {
|
if (testInfo.status !== 'passed' && testInfo.status !== 'skipped' && !process.env.PWTEST_DEBUG) {
|
||||||
for (const process of processes) {
|
for (const process of processes) {
|
||||||
console.log('====== ' + process.params.command.join(' '));
|
console.log('====== ' + process.params.command.join(' '));
|
||||||
|
|||||||
@ -73,8 +73,8 @@ export const test = contextTest.extend<CLITestArgs>({
|
|||||||
cli = new CLIMock(childProcess, browserName, channel, headless, cliArgs, launchOptions.executablePath, noAutoExit);
|
cli = new CLIMock(childProcess, browserName, channel, headless, cliArgs, launchOptions.executablePath, noAutoExit);
|
||||||
return cli;
|
return cli;
|
||||||
});
|
});
|
||||||
if (cli)
|
// Discard any exit error and let childProcess fixture report leaking processes (processwes which do not exit).
|
||||||
await cli.exited.catch(() => {});
|
cli?.exited.catch(() => {});
|
||||||
},
|
},
|
||||||
|
|
||||||
openRecorder: async ({ page, recorderPageGetter }, run) => {
|
openRecorder: async ({ page, recorderPageGetter }, run) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user