From f7f3b9340a39e048ecf0d23332e43e3cdd1c3bbe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Sep 2025 22:03:04 +0000 Subject: [PATCH 1/2] build(deps-dev): bump @sinonjs/fake-timers from 12.0.0 to 15.0.0 Bumps [@sinonjs/fake-timers](https://github.com/sinonjs/fake-timers) from 12.0.0 to 15.0.0. - [Release notes](https://github.com/sinonjs/fake-timers/releases) - [Changelog](https://github.com/sinonjs/fake-timers/blob/main/CHANGELOG.md) - [Commits](https://github.com/sinonjs/fake-timers/compare/v12.0.0...v15.0.0) --- updated-dependencies: - dependency-name: "@sinonjs/fake-timers" dependency-version: 15.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb24488ab5a..56988f209a8 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "@fastify/busboy": "3.2.0", "@matteo.collina/tspl": "^0.2.0", "@metcoder95/https-pem": "^1.0.0", - "@sinonjs/fake-timers": "^12.0.0", + "@sinonjs/fake-timers": "^15.0.0", "@types/node": "^18.19.50", "abort-controller": "^3.0.0", "borp": "^0.20.0", From 78a5ecba5b925f21d6a26c2c5a937c86f43d0fc3 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Tue, 23 Sep 2025 20:47:54 +0200 Subject: [PATCH 2/2] fix some --- test/client-keep-alive.js | 29 ++---- test/client-reconnect.js | 16 +-- test/interceptors/cache-revalidate-stale.js | 3 +- test/socket-timeout.js | 102 +++++++++++--------- 4 files changed, 70 insertions(+), 80 deletions(-) diff --git a/test/client-keep-alive.js b/test/client-keep-alive.js index e6088de2049..25d1200adb7 100644 --- a/test/client-keep-alive.js +++ b/test/client-keep-alive.js @@ -9,6 +9,13 @@ const { createServer } = require('node:net') const http = require('node:http') const FakeTimers = require('@sinonjs/fake-timers') +const clock = FakeTimers.install({ + shouldAdvanceTime: true, + toFake: ['Date'], + advanceTimeDelta: 1 +}) +after(() => clock.uninstall()) + test('keep-alive header', async (t) => { t = tspl(t, { plan: 2 }) @@ -46,9 +53,6 @@ test('keep-alive header', async (t) => { test('keep-alive header 0', async (t) => { t = tspl(t, { plan: 2 }) - const clock = FakeTimers.install() - after(() => clock.uninstall()) - const server = createServer((socket) => { socket.write('HTTP/1.1 200 OK\r\n') socket.write('Content-Length: 0\r\n') @@ -101,9 +105,7 @@ test('keep-alive header 1', async (t) => { }, (err, { body }) => { t.ifError(err) body.on('end', () => { - const timeout = setTimeout(() => { - t.fail() - }, 0) + const timeout = setTimeout(() => t.fail(), 0) client.on('disconnect', () => { t.ok(true, 'pass') clearTimeout(timeout) @@ -150,11 +152,6 @@ test('keep-alive header no postfix', async (t) => { test('keep-alive not timeout', async (t) => { t = tspl(t, { plan: 2 }) - const clock = FakeTimers.install({ - apis: ['setTimeout'] - }) - after(() => clock.uninstall()) - const server = createServer((socket) => { socket.write('HTTP/1.1 200 OK\r\n') socket.write('Content-Length: 0\r\n') @@ -192,11 +189,6 @@ test('keep-alive not timeout', async (t) => { test('keep-alive threshold', async (t) => { t = tspl(t, { plan: 2 }) - const clock = FakeTimers.install({ - apis: ['setTimeout'] - }) - after(() => clock.uninstall()) - const server = createServer((socket) => { socket.write('HTTP/1.1 200 OK\r\n') socket.write('Content-Length: 0\r\n') @@ -235,11 +227,6 @@ test('keep-alive threshold', async (t) => { test('keep-alive max keepalive', async (t) => { t = tspl(t, { plan: 2 }) - const clock = FakeTimers.install({ - apis: ['setTimeout'] - }) - after(() => clock.uninstall()) - const server = createServer((socket) => { socket.write('HTTP/1.1 200 OK\r\n') socket.write('Content-Length: 0\r\n') diff --git a/test/client-reconnect.js b/test/client-reconnect.js index 7a1725da2b0..bc05fa66b0c 100644 --- a/test/client-reconnect.js +++ b/test/client-reconnect.js @@ -6,30 +6,24 @@ const { once } = require('node:events') const { Client } = require('..') const { createServer } = require('node:http') const FakeTimers = require('@sinonjs/fake-timers') -const timers = require('../lib/util/timers') test('multiple reconnect', async (t) => { t = tspl(t, { plan: 5 }) let n = 0 - const clock = FakeTimers.install() - after(() => clock.uninstall()) - - const orgTimers = { ...timers } - Object.assign(timers, { setTimeout, clearTimeout }) - after(() => { - Object.assign(timers, orgTimers) + const clock = FakeTimers.install({ + toFake: ['Date'] }) + after(() => clock.uninstall()) const server = createServer({ joinDuplicateHeaders: true }, (req, res) => { n === 0 ? res.destroy() : res.end('ok') }) after(() => server.close()) + await once(server.listen(0), 'listening') - server.listen(0) - await once(server, 'listening') const client = new Client(`http://localhost:${server.address().port}`) - after(client.destroy.bind(client)) + after(() => client.destroy()) client.request({ path: '/', method: 'GET' }, (err, data) => { t.ok(err) diff --git a/test/interceptors/cache-revalidate-stale.js b/test/interceptors/cache-revalidate-stale.js index 30ca4d130ae..00da4cdd81f 100644 --- a/test/interceptors/cache-revalidate-stale.js +++ b/test/interceptors/cache-revalidate-stale.js @@ -9,7 +9,8 @@ const FakeTimers = require('@sinonjs/fake-timers') test('revalidates the request when the response is stale', async () => { const clock = FakeTimers.install({ - now: 1 + now: 1, + toFake: ['Date'] }) after(() => clock.uninstall()) diff --git a/test/socket-timeout.js b/test/socket-timeout.js index 5095da8f430..cc09daa6875 100644 --- a/test/socket-timeout.js +++ b/test/socket-timeout.js @@ -5,6 +5,14 @@ const { test, after } = require('node:test') const { Client, errors } = require('..') const { createServer } = require('node:http') const FakeTimers = require('@sinonjs/fake-timers') +const { once } = require('node:events') + +const clock = FakeTimers.install({ + toFake: ['setTimeout', 'Date'], + shouldAdvanceTime: true, + now: 1 +}) +after(() => clock.uninstall()) test('timeout with pipelining 1', async (t) => { t = tspl(t, { plan: 9 }) @@ -22,41 +30,44 @@ test('timeout with pipelining 1', async (t) => { }) }) after(() => server.close()) + await once(server.listen(0), 'listening') - server.listen(0, () => { - const client = new Client(`http://localhost:${server.address().port}`, { - pipelining: 1, - headersTimeout: 500, - bodyTimeout: 500 - }) - after(() => client.close()) - - client.request({ - path: '/', - method: 'GET', - opaque: 'asd' - }, (err, data) => { - t.ok(err instanceof errors.HeadersTimeoutError) // we are expecting an error - t.strictEqual(data.opaque, 'asd') - }) + const client = new Client(`http://localhost:${server.address().port}`, { + pipelining: 1, + headersTimeout: 500, + bodyTimeout: 500 + }) + after(() => client.close()) - client.request({ - path: '/', - method: 'GET' - }, (err, { statusCode, headers, body }) => { - t.ifError(err) - t.strictEqual(statusCode, 200) - t.strictEqual(headers['content-type'], 'text/plain') - const bufs = [] - body.on('data', (buf) => { - bufs.push(buf) - }) - body.on('end', () => { - t.strictEqual('hello', Buffer.concat(bufs).toString('utf8')) - }) + client.request({ + path: '/', + method: 'GET', + opaque: 'asd' + }, (err, data) => { + t.ok(err instanceof errors.HeadersTimeoutError) // we are expecting an error + t.strictEqual(data.opaque, 'asd') + }) + + client.request({ + path: '/', + method: 'GET' + }, (err, { statusCode, headers, body }) => { + t.ifError(err) + t.strictEqual(statusCode, 200) + t.strictEqual(headers['content-type'], 'text/plain') + const bufs = [] + body.on('data', (buf) => { + bufs.push(buf) + }) + body.on('end', () => { + t.strictEqual('hello', Buffer.concat(bufs).toString('utf8')) }) }) + await clock.nextAsync() + await clock.nextAsync() + await clock.nextAsync() + await t.completed }) @@ -64,8 +75,6 @@ test('Disable socket timeout', async (t) => { t = tspl(t, { plan: 2 }) const server = createServer({ joinDuplicateHeaders: true }) - const clock = FakeTimers.install() - after(clock.uninstall.bind(clock)) server.once('request', (req, res) => { setTimeout(() => { @@ -75,22 +84,21 @@ test('Disable socket timeout', async (t) => { }) after(() => server.close()) - server.listen(0, () => { - const client = new Client(`http://localhost:${server.address().port}`, { - bodyTimeout: 0, - headersTimeout: 0 + await once(server.listen(0), 'listening') + const client = new Client(`http://localhost:${server.address().port}`, { + bodyTimeout: 0, + headersTimeout: 0 + }) + after(() => client.close()) + + client.request({ path: '/', method: 'GET' }, (err, result) => { + t.ifError(err) + const bufs = [] + result.body.on('data', (buf) => { + bufs.push(buf) }) - after(() => client.close()) - - client.request({ path: '/', method: 'GET' }, (err, result) => { - t.ifError(err) - const bufs = [] - result.body.on('data', (buf) => { - bufs.push(buf) - }) - result.body.on('end', () => { - t.strictEqual('hello', Buffer.concat(bufs).toString('utf8')) - }) + result.body.on('end', () => { + t.strictEqual('hello', Buffer.concat(bufs).toString('utf8')) }) })