Skip to content

Commit 0fa8086

Browse files
committed
fix: keep idle validation on global timers
Signed-off-by: Matteo Collina <hello@matteocollina.com> (cherry picked from commit 9290322)
1 parent 8e4046e commit 0fa8086

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

lib/dispatcher/client-h1.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/* global WebAssembly */
44

55
const assert = require('node:assert')
6-
const { setTimeout: setTimeoutNative, clearTimeout: clearTimeoutNative } = require('node:timers')
76
const util = require('../core/util.js')
87
const { channels } = require('../core/diagnostics.js')
98
const timers = require('../util/timers.js')
@@ -1012,7 +1011,7 @@ function onSocketClose () {
10121011

10131012
function clearIdleSocketValidation (socket) {
10141013
if (socket[kIdleSocketValidationTimeout]) {
1015-
clearTimeoutNative(socket[kIdleSocketValidationTimeout])
1014+
clearTimeout(socket[kIdleSocketValidationTimeout])
10161015
socket[kIdleSocketValidationTimeout] = null
10171016
}
10181017

@@ -1021,7 +1020,7 @@ function clearIdleSocketValidation (socket) {
10211020

10221021
function scheduleIdleSocketValidation (client, socket) {
10231022
socket[kIdleSocketValidation] = 1
1024-
socket[kIdleSocketValidationTimeout] = setTimeoutNative(() => {
1023+
socket[kIdleSocketValidationTimeout] = setTimeout(() => {
10251024
socket[kIdleSocketValidationTimeout] = null
10261025
socket[kIdleSocketValidation] = 2
10271026

test/interceptors/cache.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('Cache Interceptor', () => {
171171

172172
test('expires caching', async () => {
173173
const clock = FakeTimers.install({
174-
shouldClearNativeTimers: true
174+
toFake: ['Date']
175175
})
176176

177177
let requestsToOrigin = 0
@@ -248,7 +248,7 @@ describe('Cache Interceptor', () => {
248248

249249
test('expires caching with Etag', async () => {
250250
const clock = FakeTimers.install({
251-
shouldClearNativeTimers: true
251+
toFake: ['Date']
252252
})
253253

254254
let requestsToOrigin = 0
@@ -326,7 +326,7 @@ describe('Cache Interceptor', () => {
326326

327327
test('max-age caching', async () => {
328328
const clock = FakeTimers.install({
329-
shouldClearNativeTimers: true
329+
toFake: ['Date']
330330
})
331331

332332
let requestsToOrigin = 0
@@ -390,7 +390,7 @@ describe('Cache Interceptor', () => {
390390

391391
test('vary headers are present in revalidation request', async () => {
392392
const clock = FakeTimers.install({
393-
shouldClearNativeTimers: true
393+
toFake: ['Date']
394394
})
395395

396396
let requestsToOrigin = 0
@@ -669,7 +669,7 @@ describe('Cache Interceptor', () => {
669669

670670
test('stale-if-error (response)', async () => {
671671
const clock = FakeTimers.install({
672-
shouldClearNativeTimers: true
672+
toFake: ['Date']
673673
})
674674

675675
let requestsToOrigin = 0
@@ -751,7 +751,7 @@ describe('Cache Interceptor', () => {
751751
describe('Client-side directives', () => {
752752
test('max-age', async () => {
753753
const clock = FakeTimers.install({
754-
shouldClearNativeTimers: true
754+
toFake: ['Date']
755755
})
756756

757757
let requestsToOrigin = 0
@@ -812,7 +812,7 @@ describe('Cache Interceptor', () => {
812812

813813
test('max-stale', async () => {
814814
const clock = FakeTimers.install({
815-
shouldClearNativeTimers: true
815+
toFake: ['Date']
816816
})
817817

818818
let requestsToOrigin = 0
@@ -885,7 +885,7 @@ describe('Cache Interceptor', () => {
885885

886886
test('min-fresh', async () => {
887887
const clock = FakeTimers.install({
888-
shouldClearNativeTimers: true
888+
toFake: ['Date']
889889
})
890890

891891
let requestsToOrigin = 0
@@ -1103,7 +1103,7 @@ describe('Cache Interceptor', () => {
11031103

11041104
test('stale-if-error', async () => {
11051105
const clock = FakeTimers.install({
1106-
shouldClearNativeTimers: true
1106+
toFake: ['Date']
11071107
})
11081108

11091109
let requestsToOrigin = 0
@@ -1988,7 +1988,7 @@ describe('Cache Interceptor', () => {
19881988

19891989
describe('determineDeleteAt', () => {
19901990
test('max-age response has deleteAt proportional to freshness lifetime, not 1 year', async () => {
1991-
const clock = FakeTimers.install({ now: 1000 })
1991+
const clock = FakeTimers.install({ now: 1000, toFake: ['Date'] })
19921992
after(() => clock.uninstall())
19931993

19941994
const store = new MemoryCacheStore()
@@ -2024,7 +2024,7 @@ describe('Cache Interceptor', () => {
20242024
})
20252025

20262026
test('immutable response has deleteAt of ~1 year', async () => {
2027-
const clock = FakeTimers.install({ now: 1000 })
2027+
const clock = FakeTimers.install({ now: 1000, toFake: ['Date'] })
20282028
after(() => clock.uninstall())
20292029

20302030
const store = new MemoryCacheStore()
@@ -2058,7 +2058,7 @@ describe('Cache Interceptor', () => {
20582058
})
20592059

20602060
test('stale-while-revalidate extends deleteAt beyond staleAt', async () => {
2061-
const clock = FakeTimers.install({ now: 1000 })
2061+
const clock = FakeTimers.install({ now: 1000, toFake: ['Date'] })
20622062
after(() => clock.uninstall())
20632063

20642064
const store = new MemoryCacheStore()

0 commit comments

Comments
 (0)