Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 5, 2023
1 parent 01b972b commit 2750939
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
19 changes: 9 additions & 10 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function onTimeout () {
}

if (timer.expires === 0) {
timer.destroyed = true
timer.active = false
if (idx !== len - 1) {
fastTimers[idx] = fastTimers.pop()
} else {
Expand Down Expand Up @@ -53,20 +53,19 @@ class Timeout {
this.callback = callback
this.delay = delay
this.opaque = opaque
this.expires = fastNow + delay

this.destroyed = false
fastTimers.push(this)
this.expires = 0
this.active = false

if (!fastNowTimeout || fastTimers.length === 1) {
refreshTimeout()
}
this.refresh()
}

refresh () {
if (this.destroyed) {
this.destroyed = false
if (!this.active) {
this.active = true
fastTimers.push(this)
if (!fastNowTimeout || fastTimers.length === 1) {
refreshTimeout()
}
}

this.expires = fastNow + this.delay
Expand Down
76 changes: 38 additions & 38 deletions test/client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ const { Readable } = require('stream')
const FakeTimers = require('@sinonjs/fake-timers')
const timers = require('../lib/timers')

// test('refresh timeout on pause', (t) => {
// t.plan(1)

// const server = createServer((req, res) => {
// res.flushHeaders()
// })
// t.teardown(server.close.bind(server))

// server.listen(0, () => {
// const client = new Client(`http://localhost:${server.address().port}`, {
// bodyTimeout: 500
// })
// t.teardown(client.destroy.bind(client))

// client.dispatch({
// path: '/',
// method: 'GET'
// }, {
// onConnect () {
// },
// onHeaders (statusCode, headers, resume) {
// setTimeout(() => {
// resume()
// }, 1000)
// return false
// },
// onData () {

// },
// onComplete () {

// },
// onError (err) {
// t.type(err, errors.BodyTimeoutError)
// }
// })
// })
// })
test('refresh timeout on pause', (t) => {
t.plan(1)

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

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
bodyTimeout: 500
})
t.teardown(client.destroy.bind(client))

client.dispatch({
path: '/',
method: 'GET'
}, {
onConnect () {
},
onHeaders (statusCode, headers, resume) {
setTimeout(() => {
resume()
}, 1000)
return false
},
onData () {

},
onComplete () {

},
onError (err) {
t.type(err, errors.BodyTimeoutError)
}
})
})
})

test('start headers timeout after request body', (t) => {
t.plan(2)
Expand Down

0 comments on commit 2750939

Please sign in to comment.