-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: throw on retry when payload is consume by downstream (#3389)
* fix: throw on retry when payload is consumed * fixup * fixup
- Loading branch information
1 parent
4b0921c
commit 71121e5
Showing
2 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
const { tspl } = require('@matteo.collina/tspl') | ||
const { test, after } = require('node:test') | ||
const { createServer } = require('node:http') | ||
const { once } = require('node:events') | ||
|
||
const { fetch, Agent, RetryAgent } = require('..') | ||
|
||
test('https://github.com/nodejs/undici/issues/3356', async (t) => { | ||
t = tspl(t, { plan: 3 }) | ||
|
||
let shouldRetry = true | ||
const server = createServer() | ||
server.on('request', (req, res) => { | ||
res.writeHead(200, { 'content-type': 'text/plain' }) | ||
if (shouldRetry) { | ||
shouldRetry = false | ||
|
||
res.flushHeaders() | ||
res.write('h') | ||
setTimeout(() => { res.end('ello world!') }, 100) | ||
} else { | ||
res.end('hello world!') | ||
} | ||
}) | ||
|
||
server.listen(0) | ||
|
||
await once(server, 'listening') | ||
|
||
after(async () => { | ||
server.close() | ||
|
||
await once(server, 'close') | ||
}) | ||
|
||
const agent = new RetryAgent(new Agent({ bodyTimeout: 50 }), { | ||
errorCodes: ['UND_ERR_BODY_TIMEOUT'] | ||
}) | ||
|
||
const response = await fetch(`http://localhost:${server.address().port}`, { | ||
dispatcher: agent | ||
}) | ||
setTimeout(async () => { | ||
try { | ||
t.equal(response.status, 200) | ||
// consume response | ||
await response.text() | ||
} catch (err) { | ||
t.equal(err.name, 'TypeError') | ||
t.equal(err.cause.code, 'UND_ERR_REQ_RETRY') | ||
} | ||
}, 200) | ||
|
||
await t.completed | ||
}) |