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

This commit is contained in:
Max Schmitt 2023-04-06 20:09:19 +02:00 коммит произвёл GitHub
Родитель 44b63b042e
Коммит 2df0f0738d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 15 добавлений и 6 удалений

Просмотреть файл

@ -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(' '));

Просмотреть файл

@ -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) => {