Skip to content

Commit 904b9db

Browse files
committed
test: cleanup early 413 upload timer
1 parent facb3bc commit 904b9db

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

test/server-socket.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ describe('autoCleanupIncoming: true (default)', () => {
249249
let responseBody = ''
250250
let responseStatus = 0
251251
let requestError: Error | null = null
252+
let sendTimer: ReturnType<typeof setTimeout> | undefined
253+
254+
const cleanupSendTimer = () => {
255+
if (sendTimer) {
256+
clearTimeout(sendTimer)
257+
sendTimer = undefined
258+
}
259+
}
252260

253261
const req = request(
254262
{
@@ -275,6 +283,7 @@ describe('autoCleanupIncoming: true (default)', () => {
275283

276284
req.on('close', reqClose)
277285
req.on('error', (err) => {
286+
cleanupSendTimer()
278287
requestError = err
279288
})
280289

@@ -288,11 +297,12 @@ describe('autoCleanupIncoming: true (default)', () => {
288297
}
289298
req.write(Buffer.alloc(Math.min(chunkSize, totalSize - offset)))
290299
offset += chunkSize
291-
setTimeout(sendChunk, 5)
300+
sendTimer = setTimeout(sendChunk, 5)
292301
}
293302
sendChunk()
294303

295304
await Promise.all([reqPromise, resPromise])
305+
cleanupSendTimer()
296306
expect(responseStatus).toBe(413)
297307
if (!expectEmptyBody) {
298308
expect(responseBody).toBe('Payload Too Large')

0 commit comments

Comments
 (0)