Skip to content

Commit

Permalink
Make test pass in v19.x (nodejs#1879)
Browse files Browse the repository at this point in the history
* Make test pass in v19.x

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* enable v19

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* github CI timeout

Signed-off-by: Matteo Collina <hello@matteocollina.com>

Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina authored and anonrig committed Apr 4, 2023
1 parent a02e8c6 commit aad6fd6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on: [push, pull_request]
jobs:
build:
name: Test
timeout-minutes: 15
uses: pkgjs/action/.github/workflows/node-test.yaml@v0.1
with:
runs-on: ubuntu-latest, windows-latest
Expand All @@ -22,7 +23,6 @@ jobs:
exclude: |
- runs-on: windows-latest
node-version: 16
- node-version: 19
automerge:
if: >
github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
Expand Down
11 changes: 7 additions & 4 deletions test/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { test } = require('tap')
const { BalancedPool, Pool, Client, errors } = require('..')
const { createServer } = require('http')
const { promisify } = require('util')
const semver = require('semver')

test('throws when factory is not a function', (t) => {
t.plan(2)
Expand Down Expand Up @@ -433,7 +434,10 @@ const cases = [
expected: ['A', 'B', 'C', 'A', 'B', 'C/connectionRefused', 'A', 'B', 'A', 'B', 'A', 'B', 'C', 'A', 'B', 'C'],
expectedConnectionRefusedErrors: 1,
expectedSocketErrors: 0,
expectedRatios: [0.34, 0.34, 0.32]
expectedRatios: [0.34, 0.34, 0.32],

// Skip because the behavior of Node.js has changed
skip: semver.satisfies(process.version, '>= 19.0.0')
},

// 8
Expand Down Expand Up @@ -476,8 +480,8 @@ const cases = [

]

for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, maxWeightPerServer, errorPenalty = 10 }] of cases.entries()) {
test(`weighted round robin - case ${index}`, async (t) => {
for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, maxWeightPerServer, errorPenalty = 10, only = false, skip = false }] of cases.entries()) {
test(`weighted round robin - case ${index}`, { only, skip }, async (t) => {
// cerate an array to store succesfull reqeusts
const requestLog = []

Expand Down Expand Up @@ -512,7 +516,6 @@ for (const [index, { config, expected, expectedRatios, iterations = 9, expectedC
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)

serverWithError.requestsCount++

if (e.code === 'ECONNREFUSED') {
Expand Down
26 changes: 24 additions & 2 deletions test/fetch/abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { fetch } = require('../..')
const { createServer } = require('http')
const { once } = require('events')
const { DOMException } = require('../../lib/fetch/constants')
const semver = require('semver')

const { AbortController: NPMAbortController } = require('abort-controller')

Expand Down Expand Up @@ -36,13 +37,13 @@ test('Allow the usage of custom implementation of AbortController', async (t) =>
}
})

test('allows aborting with custom errors', { skip: process.version.startsWith('v16.') }, async (t) => {
test('allows aborting with custom errors', { skip: semver.satisfies(process.version, '16.x') }, async (t) => {
const server = createServer().listen(0)

t.teardown(server.close.bind(server))
await once(server, 'listening')

t.test('Using AbortSignal.timeout', async (t) => {
t.test('Using AbortSignal.timeout without cause', { skip: semver.satisfies(process.version, '>= 19.0.0') }, async (t) => {
await t.rejects(
fetch(`http://localhost:${server.address().port}`, {
signal: AbortSignal.timeout(50)
Expand All @@ -54,6 +55,27 @@ test('allows aborting with custom errors', { skip: process.version.startsWith('v
)
})

t.test('Using AbortSignal.timeout with cause', { skip: semver.satisfies(process.version, '< 19.0.0') }, async (t) => {
t.plan(2)

try {
await fetch(`http://localhost:${server.address().port}`, {
signal: AbortSignal.timeout(50)
})
} catch (err) {
if (err.name === 'TypeError') {
const cause = err.cause
t.equal(cause.name, 'HeadersTimeoutError')
t.equal(cause.code, 'UND_ERR_HEADERS_TIMEOUT')
} else if (err.name === 'TimeoutError') {
t.equal(err.code, DOMException.TIMEOUT_ERR)
t.equal(err.cause, undefined)
} else {
t.error(err)
}
}
})

t.test('Error defaults to an AbortError DOMException', async (t) => {
const ac = new AbortController()
ac.abort() // no reason
Expand Down

0 comments on commit aad6fd6

Please sign in to comment.