Skip to content

Commit 1a0cf69

Browse files
committed
Merge branch 'main' into update-tests-v19
2 parents ea85ea7 + 25a8aac commit 1a0cf69

8 files changed

Lines changed: 30 additions & 17 deletions

File tree

docs/api/Dispatcher.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ try {
631631

632632
A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream.
633633

634-
As demonstrated in [Example 1 - Basic GET stream request](#example-1-basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2-stream-to-fastify-response) for more details.
634+
As demonstrated in [Example 1 - Basic GET stream request](#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2---stream-to-fastify-response) for more details.
635635

636636
Arguments:
637637

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w",
5656
"test:typescript": "tsd && tsc test/imports/undici-import.ts",
5757
"test:websocket": "node scripts/verifyVersion.js 18 || tap test/websocket/*.js",
58-
"test:wpt": "node scripts/verifyVersion 18 || (node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node test/wpt/start-websockets.mjs)",
58+
"test:wpt": "node scripts/verifyVersion 18 || (node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node --no-warnings test/wpt/start-websockets.mjs)",
5959
"coverage": "nyc --reporter=text --reporter=html npm run test",
6060
"coverage:ci": "nyc --reporter=lcov npm run test",
6161
"bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run",

test/wpt/runner/runner/runner.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { deepStrictEqual } from 'node:assert'
2-
import { EventEmitter } from 'node:events'
2+
import { EventEmitter, once } from 'node:events'
33
import { readdirSync, readFileSync, statSync } from 'node:fs'
4+
import { cpus } from 'node:os'
45
import { basename, isAbsolute, join, resolve } from 'node:path'
56
import { fileURLToPath } from 'node:url'
67
import { Worker } from 'node:worker_threads'
@@ -82,10 +83,11 @@ export class WPTRunner extends EventEmitter {
8283
return [...files]
8384
}
8485

85-
run () {
86+
async run () {
8687
const workerPath = fileURLToPath(join(import.meta.url, '../worker.mjs'))
8788
/** @type {Set<Worker>} */
8889
const activeWorkers = new Set()
90+
let finishedFiles = 0
8991

9092
for (const test of this.#files) {
9193
const code = test.includes('.sub.')
@@ -95,6 +97,7 @@ export class WPTRunner extends EventEmitter {
9597

9698
if (this.#status[basename(test)]?.skip) {
9799
this.#stats.skipped += 1
100+
finishedFiles++
98101
continue
99102
}
100103

@@ -131,10 +134,14 @@ export class WPTRunner extends EventEmitter {
131134
activeWorkers.delete(worker)
132135
clearTimeout(timeout)
133136

134-
if (activeWorkers.size === 0) {
137+
if (++finishedFiles === this.#files.length) {
135138
this.handleRunnerCompletion()
136139
}
137140
})
141+
142+
if (activeWorkers.size === cpus().length) {
143+
await once(worker, 'exit')
144+
}
138145
}
139146
}
140147

test/wpt/server/server.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ send({ server: `http://localhost:${server.address().port}` })
354354

355355
process.on('message', (message) => {
356356
if (message === 'shutdown') {
357-
server.close((err) => err ? send(err) : send({ message: 'shutdown' }))
357+
server.close((err) => process.exit(err ? 1 : 0))
358358
}
359359
})
360360

test/wpt/start-FileAPI.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ const child = fork(serverPath, [], {
1010
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
1111
})
1212

13+
child.on('exit', (code) => process.exit(code))
14+
1315
for await (const [message] of on(child, 'message')) {
1416
if (message.server) {
1517
const runner = new WPTRunner('FileAPI', message.server)
1618
runner.run()
1719

1820
runner.once('completion', () => {
19-
child.send('shutdown')
21+
if (child.connected) {
22+
child.send('shutdown')
23+
}
2024
})
21-
} else if (message.message === 'shutdown') {
22-
process.exit()
2325
}
2426
}

test/wpt/start-fetch.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ const child = fork(serverPath, [], {
1010
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
1111
})
1212

13+
child.on('exit', (code) => process.exit(code))
14+
1315
for await (const [message] of on(child, 'message')) {
1416
if (message.server) {
1517
const runner = new WPTRunner('fetch', message.server)
1618
runner.run()
1719

1820
runner.once('completion', () => {
19-
child.send('shutdown')
21+
if (child.connected) {
22+
child.send('shutdown')
23+
}
2024
})
21-
} else if (message.message === 'shutdown') {
22-
process.exit()
2325
}
2426
}

test/wpt/start-mimesniff.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ const child = fork(serverPath, [], {
1010
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
1111
})
1212

13+
child.on('exit', (code) => process.exit(code))
14+
1315
for await (const [message] of on(child, 'message')) {
1416
if (message.server) {
1517
const runner = new WPTRunner('mimesniff', message.server)
1618
runner.run()
1719

1820
runner.once('completion', () => {
19-
child.send('shutdown')
21+
if (child.connected) {
22+
child.send('shutdown')
23+
}
2024
})
21-
} else if (message.message === 'shutdown') {
22-
process.exit()
2325
}
2426
}

test/wpt/start-websockets.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const child = fork(serverPath, [], {
1010
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
1111
})
1212

13+
child.on('exit', (code) => process.exit(code))
14+
1315
for await (const [message] of on(child, 'message')) {
1416
if (message.server) {
1517
const runner = new WPTRunner('websockets', message.server)
@@ -20,7 +22,5 @@ for await (const [message] of on(child, 'message')) {
2022
child.send('shutdown')
2123
}
2224
})
23-
} else if (message.message === 'shutdown') {
24-
process.exit()
2525
}
2626
}

0 commit comments

Comments
 (0)