-
Notifications
You must be signed in to change notification settings - Fork 572
/
Copy pathissue-3410.js
88 lines (69 loc) · 2.17 KB
/
issue-3410.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict'
const { tspl } = require('@matteo.collina/tspl')
const { fork } = require('node:child_process')
const { resolve: pathResolve } = require('node:path')
const { describe, test } = require('node:test')
const { Agent, fetch, setGlobalDispatcher } = require('..')
const { eventLoopBlocker } = require('./utils/event-loop-blocker')
describe('https://github.com/nodejs/undici/issues/3410', () => {
test('FastTimers', async (t) => {
t = tspl(t, { plan: 1 })
// Spawn a server in a new process to avoid effects from the blocking event loop
const {
serverProcess,
address
} = await new Promise((resolve, reject) => {
const childProcess = fork(
pathResolve(__dirname, './utils/hello-world-server.js'),
[],
{ windowsHide: true }
)
childProcess.on('message', (address) => {
resolve({
serverProcess: childProcess,
address
})
})
childProcess.on('error', err => {
reject(err)
})
})
const connectTimeout = 2000
setGlobalDispatcher(new Agent({ connectTimeout }))
const fetchPromise = fetch(address)
eventLoopBlocker(3000)
const response = await fetchPromise
t.equal(await response.text(), 'Hello World')
serverProcess.kill('SIGKILL')
})
test('native Timers', async (t) => {
t = tspl(t, { plan: 1 })
// Spawn a server in a new process to avoid effects from the blocking event loop
const {
serverProcess,
address
} = await new Promise((resolve, reject) => {
const childProcess = fork(
pathResolve(__dirname, './utils/hello-world-server.js'),
[],
{ windowsHide: true }
)
childProcess.on('message', (address) => {
resolve({
serverProcess: childProcess,
address
})
})
childProcess.on('error', err => {
reject(err)
})
})
const connectTimeout = 900
setGlobalDispatcher(new Agent({ connectTimeout }))
const fetchPromise = fetch(address)
eventLoopBlocker(1500)
const response = await fetchPromise
t.equal(await response.text(), 'Hello World')
serverProcess.kill('SIGKILL')
})
})