Skip to content

Commit cf4d90d

Browse files
authored
Fix broken test on linux (#2699)
* fix pull-dont-push test on linux Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]>
1 parent a0812d8 commit cf4d90d

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

lib/fetch/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,11 @@ function fetchFinale (fetchParams, response) {
11001100
const byteStream = new ReadableStream({
11011101
readableStream: transformStream.readable,
11021102
async pull (controller) {
1103+
// TODO(mcollina): removen this block, not sure why pull() is called twice
1104+
if (this.readableStream.locked) {
1105+
return
1106+
}
1107+
11031108
const reader = this.readableStream.getReader()
11041109

11051110
while (controller.desiredSize >= 0) {
@@ -2021,7 +2026,9 @@ async function httpNetworkFetch (
20212026
// into stream.
20222027
const buffer = new Uint8Array(bytes)
20232028
if (buffer.byteLength) {
2024-
fetchParams.controller.controller.enqueue(buffer)
2029+
try {
2030+
fetchParams.controller.controller.enqueue(buffer)
2031+
} catch {}
20252032
}
20262033

20272034
// 8. If stream is errored, then terminate the ongoing fetch.

test/fetch/pull-dont-push.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ const { setTimeout: sleep } = require('timers/promises')
1010

1111
const { closeServerAsPromise } = require('../utils/node-http')
1212

13-
test('Allow the usage of custom implementation of AbortController', async (t) => {
13+
test('pull dont\'t push', async (t) => {
1414
let count = 0
1515
let socket
16+
const max = 1_000_000
1617
const server = createServer((req, res) => {
1718
res.statusCode = 200
1819
socket = res.socket
@@ -21,7 +22,7 @@ test('Allow the usage of custom implementation of AbortController', async (t) =>
2122
const stream = new Readable({
2223
read () {
2324
this.push('a')
24-
if (count++ > 1000000) {
25+
if (count++ > max) {
2526
this.push(null)
2627
}
2728
}
@@ -42,12 +43,14 @@ test('Allow the usage of custom implementation of AbortController', async (t) =>
4243
// Some time is needed to fill the buffer
4344
await sleep(1000)
4445

45-
assert.strictEqual(socket.bytesWritten < 1024 * 1024, true) // 1 MB
4646
socket.destroy()
47+
assert.strictEqual(count < max, true) // the stream should be closed before the max
4748

4849
// consume the stream
4950
try {
5051
/* eslint-disable-next-line no-empty, no-unused-vars */
51-
for await (const chunk of res.body) {}
52+
for await (const chunk of res.body) {
53+
// process._rawDebug('chunk', chunk)
54+
}
5255
} catch {}
5356
})

test/wpt/runner/runner.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export class WPTRunner extends EventEmitter {
254254
this.#stats.completed += 1
255255

256256
if (message.result.status === 1) {
257+
let expectedFailure = false
257258
this.#stats.failed += 1
258259

259260
wptResult?.subtests.push({
@@ -265,6 +266,7 @@ export class WPTRunner extends EventEmitter {
265266
const name = normalizeName(message.result.name)
266267

267268
if (file.flaky?.includes(name)) {
269+
expectedFailure = true
268270
this.#stats.expectedFailures += 1
269271
} else if (file.allowUnexpectedFailures || topLevel.allowUnexpectedFailures || file.fail?.includes(name)) {
270272
if (!file.allowUnexpectedFailures && !topLevel.allowUnexpectedFailures) {
@@ -274,11 +276,15 @@ export class WPTRunner extends EventEmitter {
274276
}
275277
}
276278

279+
expectedFailure = true
277280
this.#stats.expectedFailures += 1
278281
} else {
279282
process.exitCode = 1
280283
console.error(message.result)
281284
}
285+
if (!expectedFailure) {
286+
process._rawDebug(`Failed test: ${path}`)
287+
}
282288
} else {
283289
wptResult?.subtests.push({
284290
status: 'PASS',

0 commit comments

Comments
 (0)