This commit is contained in:
Simon Knott 2024-11-07 11:08:53 +01:00
parent 5c89e57ca1
commit 8c7b02ef7f
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 7 additions and 3 deletions

View file

@ -126,11 +126,15 @@ export class WebServerPlugin implements TestRunnerPlugin {
const success = launchedProcess.kill(signal); const success = launchedProcess.kill(signal);
if (!success) if (!success)
throw new Error(`SIGINT didn't succeed, fall back to non-graceful shutdown`); throw new Error(`signal didn't succeed, fall back to non-graceful shutdown`);
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const timer = timeout !== 0 const timer = timeout !== 0
? setTimeout(() => reject(new Error(`process didn't close gracefully within timeout, falling back to SIGKILL`)), timeout) ? setTimeout(() => {
// @ts-expect-error. SIGINT didn't kill the process, but `processLauncher` will only attempt killing it if this is false
launchedProcess.killed = false;
reject(new Error(`process didn't close gracefully within timeout, falling back to SIGKILL`));
}, timeout)
: undefined; : undefined;
launchedProcess.once('exit', () => { launchedProcess.once('exit', () => {
clearTimeout(timer); clearTimeout(timer);

View file

@ -756,7 +756,7 @@ test.describe('kill option', () => {
process.on('SIGINT', () => { console.log('%%webserver received SIGINT but stubbornly refuses to wind down') }) 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') }) process.on('SIGTERM', () => { console.log('%%webserver received SIGTERM but stubbornly refuses to wind down') })
const server = require('http').createServer((req, res) => { res.end("ok"); }) const server = require('http').createServer((req, res) => { res.end("ok"); })
server.listen(process.argv[2], () => { console.log('webserver started'); }); server.listen(process.argv[2]);
`, `,
'test.spec.ts': ` 'test.spec.ts': `
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';