Skip to content

Commit 8e69a9f

Browse files
committed
fix(test): use explicit dispatcher in content-encoding tests
The first describe block used the global agent, leaving pooled connections alive after server.closeAllConnections() sent RST. On macOS, the async RST delivery could surface as ECONNRESET in the next describe block's fetch call. Give each block its own Client and await cleanup to eliminate the race. Signed-off-by: Sam Mayer <sam.mayer@defenseunicorns.com>
1 parent 29ddaeb commit 8e69a9f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

test/fetch/encoding.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('content-encoding handling', () => {
1010
const zstdText = Buffer.from('KLUv/QBYaQAASGVsbG8sIFdvcmxkIQ==', 'base64')
1111

1212
let server
13+
let client
1314
before(async () => {
1415
server = createServer({
1516
noDelay: true
@@ -47,16 +48,19 @@ describe('content-encoding handling', () => {
4748
}
4849
})
4950
await once(server.listen(0), 'listening')
51+
client = new Client(`http://localhost:${server.address().port}`)
5052
})
5153

52-
after(() => {
54+
after(async () => {
55+
await client.close()
5356
server.closeAllConnections?.()
5457
server.close()
58+
await once(server, 'close')
5559
})
5660

5761
test('content-encoding header', async (t) => {
5862
const response = await fetch(`http://localhost:${server.address().port}`, {
59-
keepalive: false,
63+
dispatcher: client,
6064
headers: { 'accept-encoding': 'deflate, gzip' }
6165
})
6266

@@ -67,7 +71,7 @@ describe('content-encoding handling', () => {
6771

6872
test('content-encoding header is case-iNsENsITIve', async (t) => {
6973
const response = await fetch(`http://localhost:${server.address().port}`, {
70-
keepalive: false,
74+
dispatcher: client,
7175
headers: { 'accept-encoding': 'DeFlAtE, GzIp' }
7276
})
7377

@@ -80,7 +84,7 @@ describe('content-encoding handling', () => {
8084
{ skip: typeof require('node:zlib').createZstdDecompress !== 'function' },
8185
async (t) => {
8286
const response = await fetch(`http://localhost:${server.address().port}`, {
83-
keepalive: false,
87+
dispatcher: client,
8488
headers: { 'accept-encoding': 'zstd' }
8589
})
8690

0 commit comments

Comments
 (0)