runwarm 0.1.0-alpha.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ First release outside the alpha channel. RunWarm follows semantic versioning: until 1.0.0, a minor version can change options or profile hook behavior, and each such change is marked below.
6
+
7
+ - **Changed:** the case name passed by `t.withApp()` is now the full name of `t`, including the test file and parent tests, such as `test/orders.test.js > checkout > pays by card`. Profiles that match on the bare test name need updating. Names passed to `withApp(caseName, callback)` are unchanged.
8
+ - **Changed:** a worker retired after a failed preparation or reset, or a disconnected client, now runs its `stop` hook before it is killed, unless it timed out. `stop` must cope with an application whose state was not reset.
9
+ - `app-timeout` option for the profile hook timeout, still 30 seconds by default.
10
+ - Application workers no longer inherit the pool's socket address and token.
11
+ - Shutdown stops every worker even when one `stop` hook fails, and reports all failures.
12
+ - The control message size limit applies to each message.
13
+ - The README explains how to use a TypeScript profile and shows benchmark results for 1,000 HTTP test files and for smaller suites on Linux, Windows and macOS.
14
+
15
+ ## 0.1.0-alpha.1
16
+
17
+ - Type declarations for `defineAppProfile` and `withApp`.
18
+ - `funding` field pointing to GitHub Sponsors.
19
+ - The npm page now shows the npm install instructions and describes how the pool works without a Mermaid diagram.
20
+
3
21
  ## 0.1.0-alpha.0
4
22
 
5
23
  First pre-release.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <p align="center"><strong>A node-tap plugin that keeps your application running between integration tests.</strong></p>
4
4
 
5
5
  <p align="center">
6
- <a href="package.json"><img alt="Project version" src="https://img.shields.io/github/package-json/v/fabenejr/runwarm?label=version"></a>
6
+ <a href="https://www.npmjs.com/package/runwarm"><img alt="npm version" src="https://img.shields.io/npm/v/runwarm?logo=npm"></a>
7
7
  <a href="https://github.com/fabenejr/runwarm/actions/workflows/acceptance.yml"><img alt="Acceptance tests status" src="https://github.com/fabenejr/runwarm/actions/workflows/acceptance.yml/badge.svg"></a>
8
8
  <a href="LICENSE"><img alt="MIT license" src="https://img.shields.io/github/license/fabenejr/runwarm"></a>
9
9
  </p>
@@ -29,10 +29,10 @@ When integration tests start the same app in every file, they repeat the work of
29
29
 
30
30
  ## Quick start
31
31
 
32
- RunWarm needs Node.js 22.12.0 or later and node-tap 21.8.1 or later. It is not on npm yet, so build a tarball from a clone with `npm pack` and install it in your project.
32
+ RunWarm needs Node.js 22.12.0 or later and node-tap 21.8.1 or later. Install it from npm.
33
33
 
34
34
  ```sh
35
- npm install --save-dev ./runwarm-0.1.0-alpha.0.tgz
35
+ npm install --save-dev runwarm
36
36
  npx tap plugin add runwarm/plugin
37
37
  npx tap --disable-coverage --app-profile=profile.js
38
38
  ```
@@ -51,7 +51,7 @@ t.test('a new customer has no orders', t => t.withApp(async ({ url }) => {
51
51
  }))
52
52
  ```
53
53
 
54
- Await all requests and background operations owned by the test before the callback returns. The callback also receives a `workerId` for diagnostics. The case name passed to the profile hooks is the name of `t`. Outside a `t`, or to name the case yourself, import `withApp(caseName, callback)` from `runwarm`.
54
+ Await all requests and background operations owned by the test before the callback returns. The callback also receives a `workerId` for diagnostics. The case name passed to the profile hooks is the full name of `t`, which starts with the test file and includes the parent tests, such as `test/orders.test.js > checkout > pays by card`. Outside a `t`, or to name the case yourself, import `withApp(caseName, callback)` from `runwarm`.
55
55
 
56
56
  ## Options
57
57
 
@@ -62,6 +62,7 @@ Pass them on the command line or set them in `.taprc`.
62
62
  | `app-profile` | none | Module whose default export is the application profile. The plugin stays idle without it |
63
63
  | `app-workers` | `1` | Maximum number of running applications |
64
64
  | `app-metrics` | off | Write one `runwarm metrics: {...}` JSON line to stderr when the run ends |
65
+ | `app-timeout` | `30` | Seconds each profile hook may take, including `start`. A worker that runs over is discarded |
65
66
 
66
67
  ```yaml
67
68
  app-profile: test/profile.js
@@ -77,6 +78,8 @@ The metrics report includes total duration, workers started, completed bootstrap
77
78
 
78
79
  Export the result of `defineAppProfile` as the default export of the module named by `app-profile`. The pool loads one profile per run. The repository includes working profiles for [Fastify](examples/fastify/profile.js), [Express](examples/express/profile.js), [NestJS](examples/nestjs/profile.js), and [Node.js HTTPS](examples/https/profile.js).
79
80
 
81
+ The application runs in a plain Node.js process, without the loaders tap adds to test files. A TypeScript profile (`profile.ts`) works on Node.js 22.18.0 or later, which strips types by default. On older versions, or for syntax that type stripping does not support, compile the profile first or pass a loader through `NODE_OPTIONS`.
82
+
80
83
  | Hook | Responsibility |
81
84
  | --- | --- |
82
85
  | `start({ workerId })` | Start the server on an available port on `127.0.0.1`. Wait until it can accept requests, then return an object containing its `url` and any resources the other hooks need. |
@@ -90,19 +93,13 @@ The HTTPS example reads PEM files from `EXAMPLE_TLS_CERT` and `EXAMPLE_TLS_KEY`.
90
93
 
91
94
  ### How the pool works
92
95
 
93
- ```mermaid
94
- flowchart LR
95
- subgraph Runner[tap runner]
96
- Plugin[RunWarm plugin and pool coordinator]
97
- end
98
- Runner --> Test[Test file]
99
- Test -->|Reserve and release over a local socket| Plugin
100
- Plugin -->|Lifecycle commands over IPC| Worker[Application worker]
101
- Test -->|HTTP or HTTPS| Worker
102
- Worker --> Profile[Application profile and resources]
103
- ```
96
+ 1. The tap runner loads the plugin, which starts the pool coordinator.
97
+ 2. Each test file reserves a worker from the coordinator over a local socket.
98
+ 3. The coordinator sends lifecycle commands to the application worker over IPC, and the worker runs your profile.
99
+ 4. The test sends HTTP or HTTPS requests straight to the application.
100
+ 5. On release, the worker resets the application and takes the next case.
104
101
 
105
- The runner listens on a Unix socket in a private temporary directory, or on a named pipe on Windows, with a random token for each run. Workers start on demand and callers queue in arrival order when all are busy. Test requests go directly to the application. If preparation or reset fails, or the client disconnects during a reservation, the coordinator discards the affected worker. Lifecycle commands time out after 30 seconds.
102
+ The runner listens on a Unix socket in a private temporary directory, or on a named pipe on Windows, with a random token for each run. Workers start on demand and callers queue in arrival order when all are busy. Test requests go directly to the application. If preparation or reset fails, or the client disconnects during a reservation, the coordinator runs the worker's `stop` hook while it still responds and then discards it. Lifecycle commands time out after `app-timeout` seconds. A worker that times out is discarded without `stop`. Application workers do not inherit the pool's socket address and token.
106
103
 
107
104
  ## Limitations
108
105
 
@@ -113,20 +110,64 @@ The runner listens on a Unix socket in a private temporary directory, or on a na
113
110
 
114
111
  ## Benchmarks
115
112
 
116
- The benchmark packs RunWarm, installs it in a temporary project, adds the plugin and runs the same HTTP cases with a new application per case, a new application per file and the pool.
113
+ The benchmark packs RunWarm, installs it in a temporary project, adds the plugin and runs the same HTTP cases against a real Fastify, Express or NestJS application with no artificial startup delay. Each case lists, creates and lists orders. It compares a new application per case or per file with the RunWarm pool.
114
+
115
+ ### 1,000 HTTP test files
116
+
117
+ The largest run has 1,000 tap files with one HTTP case each, 8 tap jobs and 8 pool workers. Without the pool, every file starts its own application. With it, the whole run starts 8 or fewer.
118
+
119
+ <p align="center">
120
+ <img alt="Wall time for 1,000 HTTP test files on Linux. Fastify: 502 s with a new app per case, 433 s with the RunWarm pool. Express: 534 s and 493 s. NestJS: 623 s and 464 s." src="docs/assets/benchmark-1000-wall.svg" width="760">
121
+ </p>
122
+
123
+ <p align="center">
124
+ <img alt="CPU time for 1,000 HTTP test files on Linux. Fastify: 1,728 s with a new app per case, 1,476 s with the RunWarm pool. Express: 1,761 s and 1,612 s. NestJS: 2,124 s and 1,559 s." src="docs/assets/benchmark-1000-cpu.svg" width="760">
125
+ </p>
126
+
127
+ | 1,000 files on Linux | App startups | Wall time | CPU time | Peak memory |
128
+ | --- | ---: | ---: | ---: | ---: |
129
+ | NestJS 11.2.12 | 1,000 → **8** | 623 s → **464 s** (−25%) | 2,124 s → **1,559 s** (−27%) | 1,926 → 1,991 MiB |
130
+ | Fastify 5.12.8 | 1,000 → **6** | 502 s → **433 s** (−14%) | 1,728 s → **1,476 s** (−15%) | 1,795 → 1,819 MiB |
131
+ | Express 5.3.0 | 1,000 → **7** | 534 s → **493 s** (−8%) | 1,761 s → **1,612 s** (−8%) | 1,698 → 1,800 MiB |
132
+
133
+ CPU time is the user and system time of the whole process tree, and peak memory is its proportional set size (PSS). The pool saves machine time as well as wall time: the NestJS run uses about 9 fewer CPU minutes, which matters on shared CI runners and machines that run several suites at once. Peak memory does not drop, because the 8 tap jobs and their test processes dominate it, and the warm applications add a little. The 1,000-file figures come from one round each; the [10- and 100-file runs](benchmark/results) show the same trend with 3 rounds each.
134
+
135
+ ### Smaller suites on Linux, Windows and macOS
136
+
137
+ <p align="center">
138
+ <img alt="Wall time for 120 HTTP test cases on Linux. Fastify: 14.2 s per case, 13.8 s per file, 12.1 s pooled. Express: 13.6 s, 13.7 s, 12.9 s. NestJS: 19.8 s, 18.9 s, 15.0 s." src="docs/assets/benchmark-wall-linux.svg" width="760">
139
+ </p>
140
+
141
+ <p align="center">
142
+ <img alt="Wall time for 24 HTTP test cases on Windows. Fastify: 4.1 s per case, 4.1 s per file, 3.6 s pooled. Express: 3.6 s, 3.6 s, 3.4 s. NestJS: 8.6 s, 8.0 s, 6.1 s." src="docs/assets/benchmark-wall-windows.svg" width="760">
143
+ </p>
144
+
145
+ <p align="center">
146
+ <img alt="Wall time for 24 HTTP test cases on macOS. Fastify: 4.9 s per case, 4.8 s per file, 4.5 s pooled. Express: 4.1 s, 3.6 s, 3.4 s. NestJS: 6.5 s, 6.0 s, 3.6 s." src="docs/assets/benchmark-wall-macos.svg" width="760">
147
+ </p>
148
+
149
+ | Pool vs. new app per file | Linux, 120 cases | Windows, 24 cases | macOS, 24 cases |
150
+ | --- | ---: | ---: | ---: |
151
+ | NestJS 11.2.12 | 18.9 s → **15.0 s** (−21%) | 8.0 s → **6.1 s** (−23%) | 6.0 s → **3.6 s** (−39%) |
152
+ | Fastify 5.12.8 | 13.8 s → **12.1 s** (−12%) | 4.1 s → **3.6 s** (−11%) | 4.8 s → **4.5 s** (−6%) |
153
+ | Express 5.3.0 | 13.7 s → **12.9 s** (−6%) | 3.6 s → **3.4 s** (−6%) | 3.6 s → **3.4 s** (−7%) |
154
+
155
+ These runs use 2 tap jobs and 2 pool workers and report the median of 3 rounds. On Linux the pool also cut CPU time by 6% to 23% with about the same peak memory. The gain grows with the cost of starting the application: NestJS builds a dependency injection container on every start, while a minimal Express app starts quickly and saves little, because tap still starts a process for every test file. Applications that connect to databases, run migrations or warm caches at startup should save more than these minimal examples.
156
+
157
+ ### Run it yourself
158
+
159
+ All figures come from the `Application pool benchmark` workflow on GitHub Actions (Node.js 24, node-tap 21.8.1). The raw results are in [benchmark/results](benchmark/results).
117
160
 
118
161
  ```sh
119
162
  npm run --silent benchmark -- --framework fastify --bootstrap-ms 0
120
163
  ```
121
164
 
122
- `--framework` accepts `fastify`, `express` and `nestjs`. `--resources` adds CPU and memory sampling on Linux with procps, GNU `time` and GNU `timeout`. Published figures will be added after the plugin has been measured on GitHub Actions.
165
+ `--framework` accepts `fastify`, `express` and `nestjs`. `--resources` adds CPU and memory sampling on Linux with procps, GNU `time` and GNU `timeout`. `node benchmark/chart.js` draws the charts from the result files.
123
166
 
124
167
  ## Status and roadmap
125
168
 
126
- RunWarm is an early alpha (`0.1.0-alpha.0`). The acceptance suite installs the package as a user would and covers reuse and reset, concurrent reservations, failing profiles, crashed workers, disconnected clients and interrupted runs.
169
+ RunWarm is at version 0.x: until 1.0.0, a minor version can still change options or profile hook behavior, and the [changelog](CHANGELOG.md) marks each such change. The acceptance suite installs the package as a user would and covers reuse and reset, concurrent reservations, failing profiles, crashed workers, disconnected clients and interrupted runs.
127
170
 
128
- - Publish the first pre-release to npm.
129
- - Publish benchmark results for the plugin.
130
171
  - Measure a real CI suite with a database-backed profile and background jobs.
131
172
  - Collect application coverage and track changed files for `tap --changed`.
132
173
  - Evaluate multiple profiles per run.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runwarm",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.2.0",
4
4
  "description": "node-tap plugin that keeps HTTP applications warm between integration tests",
5
5
  "keywords": [
6
6
  "tapjs plugin",
@@ -20,6 +20,7 @@
20
20
  "url": "https://github.com/fabenejr/runwarm/issues"
21
21
  },
22
22
  "homepage": "https://github.com/fabenejr/runwarm#readme",
23
+ "funding": "https://github.com/sponsors/fabenejr",
23
24
  "files": [
24
25
  "src",
25
26
  "CHANGELOG.md"
@@ -29,7 +30,10 @@
29
30
  "node": ">=22.12.0"
30
31
  },
31
32
  "exports": {
32
- ".": "./src/client.js",
33
+ ".": {
34
+ "types": "./src/client.d.ts",
35
+ "default": "./src/client.js"
36
+ },
33
37
  "./plugin": {
34
38
  "types": "./src/tap-plugin.d.ts",
35
39
  "default": "./src/tap-plugin.js"
@@ -0,0 +1,21 @@
1
+ export interface HookContext {
2
+ workerId: string
3
+ }
4
+
5
+ export interface CaseContext extends HookContext {
6
+ caseName: string
7
+ }
8
+
9
+ export interface AppProfile<App extends { url: string }> {
10
+ start(context: HookContext): App | Promise<App>
11
+ prepare?(app: App, context: CaseContext): unknown
12
+ reset(app: App, context: CaseContext): unknown
13
+ stop(app: App): unknown
14
+ }
15
+
16
+ export declare function defineAppProfile<App extends { url: string }>(profile: AppProfile<App>): AppProfile<App>
17
+
18
+ export declare function withApp<T>(
19
+ caseName: string,
20
+ run: (app: { url: string; workerId: string }) => T | Promise<T>,
21
+ ): Promise<T>
@@ -3,8 +3,8 @@ import { once } from 'node:events'
3
3
  import { Pool } from './pool.js'
4
4
  import { messages, receive, send } from './protocol.js'
5
5
 
6
- export async function startCoordinator(profileURL, size, metrics, { path, token }) {
7
- const pool = new Pool(profileURL, size, metrics)
6
+ export async function startCoordinator(profileURL, size, metrics, { path, token, timeoutMs }) {
7
+ const pool = new Pool(profileURL, size, metrics, timeoutMs)
8
8
  const sessions = new Set()
9
9
  const sockets = new Set()
10
10
 
@@ -20,7 +20,7 @@ export async function startCoordinator(profileURL, size, metrics, { path, token
20
20
  socket.setTimeout(5000, () => socket.destroy())
21
21
  const hello = await receive(stream)
22
22
  if (hello.token !== token) throw new Error('Invalid session')
23
- if (typeof hello.caseName !== 'string' || hello.caseName.length > 1024) {
23
+ if (typeof hello.caseName !== 'string' || hello.caseName.length > 4096) {
24
24
  throw new Error('Invalid test case name')
25
25
  }
26
26
  socket.setTimeout(0)
@@ -42,7 +42,8 @@ export async function startCoordinator(profileURL, size, metrics, { path, token
42
42
  send(socket, { ok: true })
43
43
  } catch (error) {
44
44
  if (slot?.worker) {
45
- await slot.worker.discard()
45
+ // The case already failed with the original error, so a failed stop is not reported.
46
+ await slot.worker.retire().catch(() => {})
46
47
  slot.worker = null
47
48
  }
48
49
  if (!socket.destroyed && socket.writable) send(socket, { error: error.message })
@@ -68,8 +69,11 @@ export async function startCoordinator(profileURL, size, metrics, { path, token
68
69
  const closed = new Promise(resolve => server.close(resolve))
69
70
  for (const socket of sockets) socket.destroy()
70
71
  await Promise.allSettled(sessions)
71
- await pool.close()
72
- await closed
72
+ try {
73
+ await pool.close()
74
+ } finally {
75
+ await closed
76
+ }
73
77
  },
74
78
  }
75
79
  }
package/src/pool.js CHANGED
@@ -1,22 +1,33 @@
1
1
  import { fork } from 'node:child_process'
2
2
  import { randomUUID } from 'node:crypto'
3
3
 
4
- function startWorker(profileURL, metrics) {
4
+ // The application under test must not open pool sessions of its own.
5
+ function workerEnv() {
6
+ const env = { ...process.env }
7
+ delete env.RUNWARM_SOCKET
8
+ delete env.RUNWARM_TOKEN
9
+ return env
10
+ }
11
+
12
+ function startWorker(profileURL, metrics, timeoutMs) {
5
13
  const workerId = randomUUID()
6
14
  const args = [profileURL, workerId]
7
15
  if (metrics) args.push('--metrics')
8
16
  const child = fork(new URL('./worker.js', import.meta.url), args, {
9
17
  stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
10
18
  execArgv: [],
19
+ env: workerEnv(),
11
20
  })
12
21
  if (metrics) child.once('spawn', () => metrics.workerStarted())
13
22
  let dead = false
23
+ // Set when a command times out: the worker may still answer it later, so it gets no further commands.
24
+ let stuck = false
14
25
  const closed = new Promise(resolve => child.once('close', () => { dead = true; resolve() }))
15
26
  // Async fork failures are also reported to any pending command.
16
27
  child.on('error', () => {})
17
28
 
18
29
  function command(action, caseName) {
19
- if (dead || !child.connected) return Promise.reject(new Error('Worker unavailable'))
30
+ if (dead || stuck || !child.connected) return Promise.reject(new Error('Worker unavailable'))
20
31
  return new Promise((resolve, reject) => {
21
32
  function finish(error, value) {
22
33
  clearTimeout(timer)
@@ -32,7 +43,10 @@ function startWorker(profileURL, metrics) {
32
43
  }
33
44
  const onExit = () => finish(new Error('Worker exited during ' + action))
34
45
  const onError = error => finish(error)
35
- const timer = setTimeout(() => finish(new Error('Worker timeout during ' + action)), 30_000)
46
+ const timer = setTimeout(() => {
47
+ stuck = true
48
+ finish(new Error('Worker timeout during ' + action))
49
+ }, timeoutMs)
36
50
  child.once('message', onMessage)
37
51
  child.once('exit', onExit)
38
52
  child.once('error', onError)
@@ -40,18 +54,30 @@ function startWorker(profileURL, metrics) {
40
54
  })
41
55
  }
42
56
 
43
- async function discard() {
57
+ // Runs the stop hook while the worker still responds, then kills it. A failed
58
+ // stop is reported after the process is gone.
59
+ async function retire() {
60
+ let failure
61
+ if (!dead && !stuck && child.connected) {
62
+ try {
63
+ await command('stop')
64
+ } catch (error) {
65
+ failure = error
66
+ }
67
+ }
44
68
  if (!dead) child.kill('SIGKILL')
45
69
  await closed
70
+ if (failure) throw failure
46
71
  }
47
72
 
48
- return { command, discard, get alive() { return child.connected && !dead } }
73
+ return { command, retire, get alive() { return child.connected && !dead && !stuck } }
49
74
  }
50
75
 
51
76
  export class Pool {
52
- constructor(profileURL, size, metrics) {
77
+ constructor(profileURL, size, metrics, timeoutMs) {
53
78
  this.profileURL = profileURL
54
79
  this.metrics = metrics
80
+ this.timeoutMs = timeoutMs
55
81
  this.slots = Array.from({ length: size }, () => ({ busy: false, worker: null }))
56
82
  this.waiters = []
57
83
  this.closing = false
@@ -78,7 +104,7 @@ export class Pool {
78
104
  }
79
105
 
80
106
  async prepare(slot, caseName) {
81
- if (!slot.worker?.alive) slot.worker = startWorker(this.profileURL, this.metrics)
107
+ if (!slot.worker?.alive) slot.worker = startWorker(this.profileURL, this.metrics, this.timeoutMs)
82
108
  return slot.worker.command('prepare', caseName)
83
109
  }
84
110
 
@@ -95,13 +121,10 @@ export class Pool {
95
121
  waiter.detach()
96
122
  waiter.reject(new Error('Pool is closing'))
97
123
  }
98
- await Promise.all(this.slots.map(async ({ worker, busy }) => {
99
- if (!worker) return
100
- try {
101
- if (worker.alive && !busy) await worker.command('stop')
102
- } finally {
103
- await worker.discard()
104
- }
105
- }))
124
+ // Every worker is retired even when another one fails to stop.
125
+ const results = await Promise.allSettled(this.slots.map(slot => slot.worker?.retire()))
126
+ const errors = results.filter(result => result.status === 'rejected').map(result => result.reason)
127
+ if (errors.length === 1) throw errors[0]
128
+ if (errors.length > 1) throw new AggregateError(errors, 'Workers failed to stop')
106
129
  }
107
130
  }
package/src/protocol.js CHANGED
@@ -4,19 +4,23 @@ export function send(socket, message) {
4
4
  socket.write(JSON.stringify(message) + '\n')
5
5
  }
6
6
 
7
+ const maxMessageBytes = 8192
8
+
7
9
  // Control messages contain only short identifiers, status and a loopback URL.
10
+ // The limit applies to each message, not to everything a chunk carries.
8
11
  export async function* messages(socket) {
9
12
  let pending = ''
10
13
  socket.setEncoding('utf8')
11
14
  for await (const chunk of socket) {
12
15
  pending += chunk
13
- if (Buffer.byteLength(pending) > 8192) throw new Error('Control message too large')
14
16
  let end
15
17
  while ((end = pending.indexOf('\n')) >= 0) {
16
18
  const line = pending.slice(0, end)
17
19
  pending = pending.slice(end + 1)
20
+ if (Buffer.byteLength(line) > maxMessageBytes) throw new Error('Control message too large')
18
21
  yield JSON.parse(line)
19
22
  }
23
+ if (Buffer.byteLength(pending) > maxMessageBytes) throw new Error('Control message too large')
20
24
  }
21
25
  }
22
26
 
@@ -2,6 +2,7 @@ export declare const config: {
2
2
  'app-profile': { type: 'string'; description: string }
3
3
  'app-workers': { type: 'number'; default: number; description: string }
4
4
  'app-metrics': { type: 'boolean'; description: string }
5
+ 'app-timeout': { type: 'number'; default: number; description: string }
5
6
  }
6
7
 
7
8
  export interface RunWarm {
package/src/tap-plugin.js CHANGED
@@ -23,6 +23,11 @@ export const config = {
23
23
  type: 'boolean',
24
24
  description: 'Print pool metrics to stderr when the run ends',
25
25
  },
26
+ 'app-timeout': {
27
+ type: 'number',
28
+ default: 30,
29
+ description: 'Seconds each profile hook may take before its worker is discarded',
30
+ },
26
31
  }
27
32
 
28
33
  function host(t) {
@@ -30,6 +35,11 @@ function host(t) {
30
35
  if (!profile) return
31
36
  const size = Number(process.env.TAP_APP_WORKERS || 1)
32
37
  if (!Number.isSafeInteger(size) || size < 1) throw new Error('app-workers must be a positive integer')
38
+ const timeoutMs = Number(process.env.TAP_APP_TIMEOUT || 30) * 1000
39
+ // setTimeout() treats delays above 2^31 - 1 ms as 1 ms.
40
+ if (!(timeoutMs > 0 && timeoutMs <= 2_147_483_647)) {
41
+ throw new Error('app-timeout must be a positive number of seconds up to 2147483')
42
+ }
33
43
  const file = resolve(profile)
34
44
  if (!statSync(file, { throwIfNoEntry: false })?.isFile()) {
35
45
  throw new Error('app-profile not found: ' + file)
@@ -44,7 +54,7 @@ function host(t) {
44
54
  process.env.RUNWARM_SOCKET = path
45
55
  process.env.RUNWARM_TOKEN = token
46
56
 
47
- const pool = startCoordinator(pathToFileURL(file).href, size, metrics, { path, token })
57
+ const pool = startCoordinator(pathToFileURL(file).href, size, metrics, { path, token, timeoutMs })
48
58
  // Reported from the teardown below.
49
59
  pool.catch(() => {})
50
60
 
@@ -59,11 +69,23 @@ function host(t) {
59
69
  }))
60
70
  }
61
71
 
72
+ // The test file followed by the names of the test and its parents, so cases with
73
+ // the same name in different files stay apart. tap's own fullname also includes
74
+ // the name of the root test, which is always "TAP".
75
+ function caseName(test) {
76
+ const names = []
77
+ let root = test
78
+ for (; root.parent; root = root.parent) names.unshift(root.name)
79
+ const suffix = ' > ' + root.name
80
+ const file = root.fullname.endsWith(suffix) ? root.fullname.slice(0, -suffix.length) : root.fullname
81
+ return [file, ...names].join(' > ')
82
+ }
83
+
62
84
  export function plugin(t, opts) {
63
85
  if (opts?.context === Symbol.for('tap.isRunner')) host(t)
64
86
  return {
65
87
  withApp(run) {
66
- return withApp(t.t.name, run)
88
+ return withApp(caseName(t.t), run)
67
89
  },
68
90
  }
69
91
  }