-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: post request signal #3354
fix: post request signal #3354
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,11 @@ test('post abort signal', async (t) => { | |
|
||
server.listen(0, async () => { | ||
const ac = new AbortController() | ||
const ures = await request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal }) | ||
const uresPromise = request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal }) | ||
ac.abort() | ||
|
||
try { | ||
const ures = await uresPromise | ||
/* eslint-disable-next-line no-unused-vars */ | ||
for await (const chunk of ures.body) { | ||
// Do nothing... | ||
|
@@ -61,9 +63,11 @@ test('post abort signal w/ reason', async (t) => { | |
server.listen(0, async () => { | ||
const ac = new AbortController() | ||
const _err = new Error() | ||
const ures = await request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal }) | ||
const uresPromise = request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal }) | ||
ac.abort(_err) | ||
|
||
try { | ||
const ures = await uresPromise | ||
/* eslint-disable-next-line no-unused-vars */ | ||
for await (const chunk of ures.body) { | ||
// Do nothing... | ||
|
@@ -74,3 +78,20 @@ test('post abort signal w/ reason', async (t) => { | |
}) | ||
await t.completed | ||
}) | ||
|
||
test('post abort signal after request completed', async (t) => { | ||
t = tspl(t, { plan: 1 }) | ||
|
||
const server = createServer((req, res) => { | ||
res.end('asd') | ||
}) | ||
after(() => server.close()) | ||
|
||
server.listen(0, async () => { | ||
const ac = new AbortController() | ||
const ures = await request(`http://0.0.0.0:${server.address().port}`, { signal: ac.signal }) | ||
ac.abort() | ||
t.equal(await ures.body.text(), 'asd') | ||
Comment on lines
+92
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ in this case the abort signal is ignored since the request is completed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these are modeled after the fetch body mixins, I'm wondering if they should throw. In the fetch spec, if a request was aborted and you attempt to read the body, it'll throw an error. @ronag wdyt? |
||
}) | ||
await t.completed | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ this test was wrong because
request
api terminates when the stream has been completely consumed, so the connection has been closed. If we postpone theawait
we can throw the abort before dispatch starts consuming the stream, so the request is actually aborted