Skip to content

Commit

Permalink
fix: Fix server closing in tests. (#3279)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed May 20, 2024
1 parent 5a564bd commit dcfaeca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
30 changes: 17 additions & 13 deletions test/fetch/client-node-max-header-size.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
'use strict'

const { execSync } = require('node:child_process')
const { tspl } = require('@matteo.collina/tspl')
const { exec } = require('node:child_process')
const { test } = require('node:test')
const assert = require('node:assert')

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

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

assert.doesNotThrow(
() => execSync(command),
/UND_ERR_HEADERS_OVERFLOW/,
'default max-http-header-size should not throw'
)
exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => {
t.strictEqual(err.code, 1)
t.strictEqual(stdout, '')
t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw')
})

exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => {
t.ifError(err)
t.strictEqual(stdout, '')
t.strictEqual(stderr, '', 'default max-http-header-size should not throw')
})

await t.completed
})
5 changes: 4 additions & 1 deletion test/utils/node-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
const util = require('node:util')

function closeServerAsPromise (server) {
return () => util.promisify(server.close.bind(server))()
return () => {
server.closeIdleConnections()
return util.promisify(server.close.bind(server))()
}
}

function closeClientAndServerAsPromise (client, server) {
Expand Down

0 comments on commit dcfaeca

Please sign in to comment.