make timeout configurable

This commit is contained in:
Simon Knott 2024-11-06 11:46:52 +01:00
parent 8283a09322
commit 184ca67221
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 5 additions and 3 deletions

View file

@ -36,7 +36,8 @@ export default defineConfig({
| `cwd` | Current working directory of the spawned process, defaults to the directory of the configuration file. | | `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"`. | | `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"`. | | `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 ## Adding a server timeout

View file

@ -31,6 +31,7 @@ export type WebServerPluginOptions = {
url?: string; url?: string;
ignoreHTTPSErrors?: boolean; ignoreHTTPSErrors?: boolean;
timeout?: number; timeout?: number;
shutdownTimeout?: number;
reuseExistingServer?: boolean; reuseExistingServer?: boolean;
cwd?: string; cwd?: string;
env?: { [key: string]: string; }; env?: { [key: string]: string; };
@ -111,10 +112,10 @@ export class WebServerPlugin implements TestRunnerPlugin {
if (!success) if (!success)
throw new Error(`SIGINT didn't succeed, fall back to non-graceful shutdown`); throw new Error(`SIGINT didn't succeed, fall back to non-graceful shutdown`);
await Promise.race([ 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 // @ts-expect-error. SIGINT didn't kill the process, but `processLauncher` will only attempt killing it if this is false
launchedProcess.killed = 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)), new Promise(f => launchedProcess.once('exit', f)),
]); ]);