From 2cf4f9ace9645ffacf547ebb0289bddfe356b862 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 24 Jan 2023 14:38:44 +0100 Subject: [PATCH 1/6] Make test pass in v19.x Signed-off-by: Matteo Collina --- test/balanced-pool.js | 11 +++++++---- test/fetch/abort.js | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/test/balanced-pool.js b/test/balanced-pool.js index 7e28da7c72d..be544887ef9 100644 --- a/test/balanced-pool.js +++ b/test/balanced-pool.js @@ -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) @@ -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 @@ -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 = [] @@ -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') { diff --git a/test/fetch/abort.js b/test/fetch/abort.js index 03ee3b44ab2..2f475464cbc 100644 --- a/test/fetch/abort.js +++ b/test/fetch/abort.js @@ -5,6 +5,8 @@ const { fetch } = require('../..') const { createServer } = require('http') const { once } = require('events') const { DOMException } = require('../../lib/fetch/constants') +const errors = require('../..').errors +const semver = require('semver') const { AbortController: NPMAbortController } = require('abort-controller') @@ -36,13 +38,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) @@ -54,6 +56,21 @@ 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(3) + + try { + await fetch(`http://localhost:${server.address().port}`, { + signal: AbortSignal.timeout(50) + }) + } catch (err) { + t.equal(err.name, 'TypeError') + const cause = err.cause + t.equal(cause.name, 'HeadersTimeoutError') + t.equal(cause.code, 'UND_ERR_HEADERS_TIMEOUT') + } + }) + t.test('Error defaults to an AbortError DOMException', async (t) => { const ac = new AbortController() ac.abort() // no reason From a3baa5785486e17d7c4f38510ae4dd5102e79859 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 24 Jan 2023 16:36:26 +0100 Subject: [PATCH 2/6] fixup Signed-off-by: Matteo Collina --- test/fetch/abort.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/fetch/abort.js b/test/fetch/abort.js index 2f475464cbc..c435f42f71c 100644 --- a/test/fetch/abort.js +++ b/test/fetch/abort.js @@ -5,7 +5,6 @@ const { fetch } = require('../..') const { createServer } = require('http') const { once } = require('events') const { DOMException } = require('../../lib/fetch/constants') -const errors = require('../..').errors const semver = require('semver') const { AbortController: NPMAbortController } = require('abort-controller') @@ -44,7 +43,7 @@ test('allows aborting with custom errors', { skip: semver.satisfies(process.vers t.teardown(server.close.bind(server)) await once(server, 'listening') - t.test('Using AbortSignal.timeout without cause', { skip: semver.satisfies(process.version, '>= 19.0.0')}, 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) @@ -56,7 +55,7 @@ test('allows aborting with custom errors', { skip: semver.satisfies(process.vers ) }) - t.test('Using AbortSignal.timeout with cause', { skip: semver.satisfies(process.version, '< 19.0.0')}, async (t) => { + t.test('Using AbortSignal.timeout with cause', { skip: semver.satisfies(process.version, '< 19.0.0') }, async (t) => { t.plan(3) try { From baacdbb394d4885dadc53b0a48eb612e05d7f9df Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 24 Jan 2023 18:34:43 +0100 Subject: [PATCH 3/6] enable v19 Signed-off-by: Matteo Collina --- .github/workflows/nodejs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index bd8de1c3450..fee9d7aace4 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -22,7 +22,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]' From e9a1ebb76f1957f684f6f31b8e40058b35c6c43f Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 25 Jan 2023 18:15:55 +0100 Subject: [PATCH 4/6] fixup Signed-off-by: Matteo Collina --- test/fetch/abort.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/fetch/abort.js b/test/fetch/abort.js index c435f42f71c..1cfa2f889a0 100644 --- a/test/fetch/abort.js +++ b/test/fetch/abort.js @@ -56,17 +56,23 @@ test('allows aborting with custom errors', { skip: semver.satisfies(process.vers }) t.test('Using AbortSignal.timeout with cause', { skip: semver.satisfies(process.version, '< 19.0.0') }, async (t) => { - t.plan(3) + t.plan(2) try { await fetch(`http://localhost:${server.address().port}`, { signal: AbortSignal.timeout(50) }) } catch (err) { - t.equal(err.name, 'TypeError') - const cause = err.cause - t.equal(cause.name, 'HeadersTimeoutError') - t.equal(cause.code, 'UND_ERR_HEADERS_TIMEOUT') + 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(cause.code, DOMException.TIMEOUT_ERR) + t.equal(err.cause, undefined) + } else { + t.error(err) + } } }) From ea85ea7503864c20400bccc94d72209d8b13fb27 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 25 Jan 2023 18:18:30 +0100 Subject: [PATCH 5/6] fixup Signed-off-by: Matteo Collina --- test/fetch/abort.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fetch/abort.js b/test/fetch/abort.js index 1cfa2f889a0..1b9f1e68e8d 100644 --- a/test/fetch/abort.js +++ b/test/fetch/abort.js @@ -67,8 +67,8 @@ test('allows aborting with custom errors', { skip: semver.satisfies(process.vers const cause = err.cause t.equal(cause.name, 'HeadersTimeoutError') t.equal(cause.code, 'UND_ERR_HEADERS_TIMEOUT') - } else if (err.name = 'TimeoutError') { - t.equal(cause.code, DOMException.TIMEOUT_ERR) + } else if (err.name === 'TimeoutError') { + t.equal(err.code, DOMException.TIMEOUT_ERR) t.equal(err.cause, undefined) } else { t.error(err) From 990302fe3126bb4516b699235f6e3fedcabc6cd6 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 26 Jan 2023 10:46:34 +0100 Subject: [PATCH 6/6] github CI timeout Signed-off-by: Matteo Collina --- .github/workflows/nodejs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index fee9d7aace4..62f85400918 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -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