Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix tests failing only on node v20 #2096

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fetch/index.js
Expand Up @@ -318,7 +318,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {

// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, cacheState) {
if (nodeMajor >= 18 && nodeMinor >= 2) {
if (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) {
performance.markResourceTiming(timingInfo, originalURL, initiatorType, globalThis, cacheState)
}
}
Expand Down
9 changes: 7 additions & 2 deletions test/autoselectfamily.js
@@ -1,12 +1,17 @@
'use strict'

const { test } = require('tap')
const { test, skip } = require('tap')
const dgram = require('dgram')
const { Resolver } = require('dns')
const dnsPacket = require('dns-packet')
const { createServer } = require('http')
const { Client, Agent, request } = require('..')
const { nodeHasAutoSelectFamily } = require('../lib/core/util')
const { nodeHasAutoSelectFamily, nodeMajor } = require('../lib/core/util')

if (nodeMajor >= 20) {
skip('some tests are failing')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @ShogunPanda these tests are failing on v20 & I had no idea how to fix them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KhafraDev This might be fixed by nodejs/node#47860. If you have a local copy of node do you mind checking?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests still seem to fail:

TAP version 13
# Subtest: with autoSelectFamily enable the request succeeds when using request
    1..3
    ok 1 - should not error
    ok 2 - should be equivalent strictly
    ok 3 - should be equivalent strictly
ok 1 - with autoSelectFamily enable the request succeeds when using request # time=34.663ms

# Subtest: with autoSelectFamily enable the request succeeds when using a client
    1..3
    ok 1 - should not error
    ok 2 - should be equivalent strictly
    ok 3 - should be equivalent strictly
ok 2 - with autoSelectFamily enable the request succeeds when using a client # time=8.505ms

# Subtest: with autoSelectFamily disabled the request fails when using request
    1..1
    not ok 1 - Cannot read properties of null (reading 'code')
      ---
      stack: >
        undici/test/autoselectfamily.js:156:26

        RequestHandler.onHeaders (undici/lib/api/api-request.js:105:14)

        Request.onHeaders (undici/lib/core/request.js:233:27)

        Parser.onHeadersComplete (undici/lib/client.js:794:23)

        wasm_on_headers_complete (undici/lib/client.js:408:30)

        null.<anonymous> (wasm://wasm/00036ac6:1:1173)

        null.<anonymous> (wasm://wasm/00036ac6:1:4100)

        null.<anonymous> (wasm://wasm/00036ac6:1:28727)

        null.<anonymous> (wasm://wasm/00036ac6:1:5454)
      at:
        line: 156
        column: 26
        file: undici/test/autoselectfamily.js
      type: TypeError
      tapCaught: uncaughtException
      test: with autoSelectFamily disabled the request fails when using request
      source: "      }, (err, { statusCode, body }) => {\r

        \        t.strictSame(err.code, 'ECONNREFUSED')\r

        -------------------------^

        \      })\r

        \    })\n"
      ...

    # failed 1 test
not ok 3 - with autoSelectFamily disabled the request fails when using request # time=27.343ms

# Subtest: with autoSelectFamily disabled the request fails when using a client
    1..1
    not ok 1 - Cannot read properties of null (reading 'code')
      ---
      stack: >
        undici/test/autoselectfamily.js:183:26

        RequestHandler.onHeaders (undici/lib/api/api-request.js:105:14)

        Request.onHeaders (undici/lib/core/request.js:233:27)

        Parser.onHeadersComplete (undici/lib/client.js:794:23)

        wasm_on_headers_complete (undici/lib/client.js:408:30)

        null.<anonymous> (wasm://wasm/00036ac6:1:1173)

        null.<anonymous> (wasm://wasm/00036ac6:1:4100)

        null.<anonymous> (wasm://wasm/00036ac6:1:28727)

        null.<anonymous> (wasm://wasm/00036ac6:1:5454)
      at:
        line: 183
        column: 26
        file: undici/test/autoselectfamily.js
      type: TypeError
      tapCaught: uncaughtException
      test: with autoSelectFamily disabled the request fails when using a client
      source: "      }, (err, { statusCode, body }) => {\r

        \        t.strictSame(err.code, 'ECONNREFUSED')\r

        -------------------------^

        \      })\r

        \    })\n"
      ...

    # failed 1 test
not ok 4 - with autoSelectFamily disabled the request fails when using a client # time=17.694ms

1..4
# failed 2 of 4 tests
# time=122.721ms

process.exit()
}

function _lookup (resolver, hostname, options, cb) {
resolver.resolve(hostname, 'ANY', (err, replies) => {
Expand Down
11 changes: 10 additions & 1 deletion test/balanced-pool.js
Expand Up @@ -515,7 +515,16 @@ for (const [index, { config, expected, expectedRatios, iterations = 9, expectedC
try {
await client.request({ path: '/', method: 'GET' })
} catch (e) {
const serverWithError = servers.find(server => server.port === e.port) || servers.find(server => server.port === e.socket.remotePort)
const serverWithError =
servers.find(server => server.port === e.port) ||
servers.find(server => {
if (typeof AggregateError === 'function' && e instanceof AggregateError) {
return e.errors.some(e => server.port === (e.socket?.remotePort ?? e.port))
}

return server.port === e.socket.remotePort
})

serverWithError.requestsCount++

if (e.code === 'ECONNREFUSED') {
Expand Down
8 changes: 4 additions & 4 deletions test/fetch/resource-timing.js
Expand Up @@ -14,6 +14,7 @@ const skip = nodeMajor < 18 || (nodeMajor === 18 && nodeMinor < 2)

test('should create a PerformanceResourceTiming after each fetch request', { skip }, (t) => {
t.plan(6)

const obs = new PerformanceObserver(list => {
const entries = list.getEntries()
t.equal(entries.length, 1)
Expand All @@ -36,11 +37,10 @@ test('should create a PerformanceResourceTiming after each fetch request', { ski

const server = createServer((req, res) => {
res.end('ok')
})
t.teardown(server.close.bind(server))

server.listen(0, async () => {
}).listen(0, async () => {
const body = await fetch(`http://localhost:${server.address().port}`)
t.strictSame('ok', await body.text())
})

t.teardown(server.close.bind(server))
})