simplify again
This commit is contained in:
parent
6d1dfe18a0
commit
907bfd2c80
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
import path from 'path';
|
||||
import net from 'net';
|
||||
import child_process from 'child_process'
|
||||
|
||||
import { colors, debug } from 'playwright-core/lib/utilsBundle';
|
||||
import { raceAgainstDeadline, launchProcess, monotonicTime, isURLAvailable } from 'playwright-core/lib/utils';
|
||||
|
|
@ -125,17 +124,9 @@ export class WebServerPlugin implements TestRunnerPlugin {
|
|||
if (!signal)
|
||||
throw new Error('skip graceful shutdown');
|
||||
|
||||
if (signal === "SIGINT") // proper usage of SIGINT is to send it to the entire process group, see https://www.cons.org/cracauer/sigint.html
|
||||
process.kill(-launchedProcess.pid!, "SIGINT");
|
||||
else { // SIGTERM is sent to the top process only, which then decides what to do
|
||||
let pid = launchedProcess.pid!;
|
||||
if (process.platform === "linux") {
|
||||
for (const webServerPID of this._queryChildProcesses(launchedProcess.pid!))
|
||||
process.kill(webServerPID, 'SIGTERM');
|
||||
} else {
|
||||
process.kill(-pid, "SIGTERM");
|
||||
}
|
||||
}
|
||||
// proper usage of SIGINT is to send it to the entire process group, see https://www.cons.org/cracauer/sigint.html
|
||||
// there's no such convention for SIGTERM, but we follow GNU bash behaviour, which is also sending to the entire process group
|
||||
process.kill(-launchedProcess.pid!, signal);
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const timer = timeout !== 0
|
||||
|
|
@ -165,11 +156,6 @@ export class WebServerPlugin implements TestRunnerPlugin {
|
|||
});
|
||||
}
|
||||
|
||||
private _queryChildProcesses(parentPID: number): number[] {
|
||||
const output = child_process.execSync(`ps --ppid ${parentPID} -o pid`, { encoding: 'utf-8' });
|
||||
return output.split("\n").map(l => parseInt(l.trim(), 10)).filter(l => !Number.isNaN(l))
|
||||
}
|
||||
|
||||
private async _waitForProcess() {
|
||||
if (!this._isAvailableCallback) {
|
||||
this._processExitedPromise.catch(() => {});
|
||||
|
|
|
|||
|
|
@ -755,17 +755,16 @@ test.describe('kill option', () => {
|
|||
'child.js': `
|
||||
process.on('SIGINT', () => { console.log('%%childprocess received SIGINT'); setTimeout(() => process.exit(), 10) })
|
||||
process.on('SIGTERM', () => { console.log('%%childprocess received SIGTERM'); setTimeout(() => process.exit(), 10) })
|
||||
process.on('message', msg => console.log(msg))
|
||||
process.on('message', () => {}) // somehow, this line is needed to receive signals in a forked child process
|
||||
`,
|
||||
'web-server.js': `
|
||||
const child = require("node:child_process").fork('./child.js', { silent: false })
|
||||
require("node:child_process").fork('./child.js', { silent: false })
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('%%webserver received SIGINT but stubbornly refuses to wind down')
|
||||
})
|
||||
process.on('SIGTERM', () => {
|
||||
console.log('%%webserver received SIGTERM but stubbornly refuses to wind down')
|
||||
child.kill('SIGINT')
|
||||
})
|
||||
|
||||
const server = require("node:http").createServer((req, res) => { res.end("ok"); })
|
||||
|
|
@ -801,7 +800,7 @@ test.describe('kill option', () => {
|
|||
|
||||
test('can be configured to send SIGTERM', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest(files({ kill: { SIGTERM: 500 } }), { workers: 1 });
|
||||
expect(parseOutputLines(result)).toEqual(['webserver received SIGTERM but stubbornly refuses to wind down', 'childprocess received SIGINT']);
|
||||
expect(parseOutputLines(result).sort()).toEqual(['childprocess received SIGTERM', 'webserver received SIGTERM but stubbornly refuses to wind down']);
|
||||
});
|
||||
|
||||
test('can be configured to send SIGINT', async ({ runInlineTest }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue