-
-
Notifications
You must be signed in to change notification settings - Fork 756
Expand file tree
/
Copy pathfetch-timeouts.js
More file actions
57 lines (48 loc) · 1.64 KB
/
fetch-timeouts.js
File metadata and controls
57 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict'
const { test } = require('node:test')
const { fetch, Agent } = require('../..')
const timers = require('../../lib/util/timers')
const { createServer } = require('node:http')
const FakeTimers = require('@sinonjs/fake-timers')
const { closeServerAsPromise } = require('../utils/node-http')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }
test('Fetch very long request, timeout overridden so no error', (t, done) => {
const minutes = 6
const msToDelay = 1000 * 60 * minutes
t.plan(1)
const clock = FakeTimers.install(fakeTimersOpts)
t.after(clock.uninstall.bind(clock))
const orgTimers = { ...timers }
Object.assign(timers, { setTimeout, clearTimeout })
t.after(() => {
Object.assign(timers, orgTimers)
})
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
setTimeout(() => {
res.end('hello')
}, msToDelay)
clock.tick(msToDelay + 1)
})
t.after(closeServerAsPromise(server))
server.listen(0, () => {
fetch(`http://localhost:${server.address().port}`, {
path: '/',
method: 'GET',
dispatcher: new Agent({
headersTimeout: 0,
connectTimeout: 0,
bodyTimeout: 0
})
})
.then((response) => response.text())
.then((response) => {
t.assert.strictEqual('hello', response)
done()
})
.catch((err) => {
// This should not happen, a timeout error should not occur
throw err
})
clock.tick(msToDelay - 1)
})
})