Skip to content

Commit

Permalink
Merge branch 'main' into update-tests-v19
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jan 26, 2023
2 parents ea85ea7 + 25a8aac commit 1a0cf69
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ try {

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.

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.
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.

Arguments:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w",
"test:typescript": "tsd && tsc test/imports/undici-import.ts",
"test:websocket": "node scripts/verifyVersion.js 18 || tap test/websocket/*.js",
"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)",
"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)",
"coverage": "nyc --reporter=text --reporter=html npm run test",
"coverage:ci": "nyc --reporter=lcov npm run test",
"bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run",
Expand Down
13 changes: 10 additions & 3 deletions test/wpt/runner/runner/runner.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { deepStrictEqual } from 'node:assert'
import { EventEmitter } from 'node:events'
import { EventEmitter, once } from 'node:events'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { cpus } from 'node:os'
import { basename, isAbsolute, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { Worker } from 'node:worker_threads'
Expand Down Expand Up @@ -82,10 +83,11 @@ export class WPTRunner extends EventEmitter {
return [...files]
}

run () {
async run () {
const workerPath = fileURLToPath(join(import.meta.url, '../worker.mjs'))
/** @type {Set<Worker>} */
const activeWorkers = new Set()
let finishedFiles = 0

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

if (this.#status[basename(test)]?.skip) {
this.#stats.skipped += 1
finishedFiles++
continue
}

Expand Down Expand Up @@ -131,10 +134,14 @@ export class WPTRunner extends EventEmitter {
activeWorkers.delete(worker)
clearTimeout(timeout)

if (activeWorkers.size === 0) {
if (++finishedFiles === this.#files.length) {
this.handleRunnerCompletion()
}
})

if (activeWorkers.size === cpus().length) {
await once(worker, 'exit')
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/wpt/server/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ send({ server: `http://localhost:${server.address().port}` })

process.on('message', (message) => {
if (message === 'shutdown') {
server.close((err) => err ? send(err) : send({ message: 'shutdown' }))
server.close((err) => process.exit(err ? 1 : 0))
}
})

Expand Down
8 changes: 5 additions & 3 deletions test/wpt/start-FileAPI.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ const child = fork(serverPath, [], {
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
})

child.on('exit', (code) => process.exit(code))

for await (const [message] of on(child, 'message')) {
if (message.server) {
const runner = new WPTRunner('FileAPI', message.server)
runner.run()

runner.once('completion', () => {
child.send('shutdown')
if (child.connected) {
child.send('shutdown')
}
})
} else if (message.message === 'shutdown') {
process.exit()
}
}
8 changes: 5 additions & 3 deletions test/wpt/start-fetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ const child = fork(serverPath, [], {
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
})

child.on('exit', (code) => process.exit(code))

for await (const [message] of on(child, 'message')) {
if (message.server) {
const runner = new WPTRunner('fetch', message.server)
runner.run()

runner.once('completion', () => {
child.send('shutdown')
if (child.connected) {
child.send('shutdown')
}
})
} else if (message.message === 'shutdown') {
process.exit()
}
}
8 changes: 5 additions & 3 deletions test/wpt/start-mimesniff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ const child = fork(serverPath, [], {
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
})

child.on('exit', (code) => process.exit(code))

for await (const [message] of on(child, 'message')) {
if (message.server) {
const runner = new WPTRunner('mimesniff', message.server)
runner.run()

runner.once('completion', () => {
child.send('shutdown')
if (child.connected) {
child.send('shutdown')
}
})
} else if (message.message === 'shutdown') {
process.exit()
}
}
4 changes: 2 additions & 2 deletions test/wpt/start-websockets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const child = fork(serverPath, [], {
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
})

child.on('exit', (code) => process.exit(code))

for await (const [message] of on(child, 'message')) {
if (message.server) {
const runner = new WPTRunner('websockets', message.server)
Expand All @@ -20,7 +22,5 @@ for await (const [message] of on(child, 'message')) {
child.send('shutdown')
}
})
} else if (message.message === 'shutdown') {
process.exit()
}
}

0 comments on commit 1a0cf69

Please sign in to comment.