Skip to content

Commit dcfaeca

Browse files
authored
fix: Fix server closing in tests. (#3279)
1 parent 5a564bd commit dcfaeca

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
'use strict'
22

3-
const { execSync } = require('node:child_process')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { exec } = require('node:child_process')
45
const { test } = require('node:test')
5-
const assert = require('node:assert')
66

77
const command = 'node -e "require(\'./undici-fetch.js\').fetch(\'https://httpbin.org/get\')"'
88

9-
test("respect Node.js' --max-http-header-size", async () => {
10-
assert.throws(
11-
() => execSync(`${command} --max-http-header-size=1`),
12-
/UND_ERR_HEADERS_OVERFLOW/,
13-
'max-http-header-size=1 should throw'
14-
)
9+
test("respect Node.js' --max-http-header-size", async (t) => {
10+
t = tspl(t, { plan: 6 })
1511

16-
assert.doesNotThrow(
17-
() => execSync(command),
18-
/UND_ERR_HEADERS_OVERFLOW/,
19-
'default max-http-header-size should not throw'
20-
)
12+
exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => {
13+
t.strictEqual(err.code, 1)
14+
t.strictEqual(stdout, '')
15+
t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw')
16+
})
17+
18+
exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => {
19+
t.ifError(err)
20+
t.strictEqual(stdout, '')
21+
t.strictEqual(stderr, '', 'default max-http-header-size should not throw')
22+
})
23+
24+
await t.completed
2125
})

test/utils/node-http.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
const util = require('node:util')
44

55
function closeServerAsPromise (server) {
6-
return () => util.promisify(server.close.bind(server))()
6+
return () => {
7+
server.closeIdleConnections()
8+
return util.promisify(server.close.bind(server))()
9+
}
710
}
811

912
function closeClientAndServerAsPromise (client, server) {

0 commit comments

Comments
 (0)