From 184ca672212058947f867d1a68d2c8922c8f1e3a Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 6 Nov 2024 11:46:52 +0100 Subject: [PATCH] make timeout configurable --- docs/src/test-webserver-js.md | 3 ++- packages/playwright/src/plugins/webServerPlugin.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/src/test-webserver-js.md b/docs/src/test-webserver-js.md index aba072d56a..62c04497ab 100644 --- a/docs/src/test-webserver-js.md +++ b/docs/src/test-webserver-js.md @@ -36,7 +36,8 @@ export default defineConfig({ | `cwd` | Current working directory of the spawned process, defaults to the directory of the configuration file. | | `stdout` | If `"pipe"`, it will pipe the stdout of the command to the process stdout. If `"ignore"`, it will ignore the stdout of the command. Default to `"ignore"`. | | `stderr` | Whether to pipe the stderr of the command to the process stderr or ignore it. Defaults to `"pipe"`. | -| `timeout` | `How long to wait for the process to start up and be available in milliseconds. Defaults to 60000. | +| `timeout` | How long to wait for the process to start up and be available in milliseconds. Defaults to 60000. | +| `shutdownTimeout` | How long to wait for the process to gracefully shut down after it was sent `SIGINT`. If exceeded, process is killed with `SIGKILL`. Defaults to 500 milliseconds. | ## Adding a server timeout diff --git a/packages/playwright/src/plugins/webServerPlugin.ts b/packages/playwright/src/plugins/webServerPlugin.ts index 0314deb245..5f5b9c8fd9 100644 --- a/packages/playwright/src/plugins/webServerPlugin.ts +++ b/packages/playwright/src/plugins/webServerPlugin.ts @@ -31,6 +31,7 @@ export type WebServerPluginOptions = { url?: string; ignoreHTTPSErrors?: boolean; timeout?: number; + shutdownTimeout?: number; reuseExistingServer?: boolean; cwd?: string; env?: { [key: string]: string; }; @@ -111,10 +112,10 @@ export class WebServerPlugin implements TestRunnerPlugin { if (!success) throw new Error(`SIGINT didn't succeed, fall back to non-graceful shutdown`); await Promise.race([ - timers.setTimeout(1000).then(() => { + timers.setTimeout(this._options.shutdownTimeout ?? 500).then(() => { // @ts-expect-error. SIGINT didn't kill the process, but `processLauncher` will only attempt killing it if this is false launchedProcess.killed = false; - return Promise.reject(new Error(`server didn't close gracefully within a second, falling back to non-graceful shutdown`)) + return Promise.reject(new Error(`server didn't close gracefully within a second, falling back to non-graceful shutdown`)); }), new Promise(f => launchedProcess.once('exit', f)), ]);