forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fetch parameters not being applied correctly (nodejs#1870)
* Fix default fetch parameters * Preserve existing behavior with 300 second timeout if not defined * Add test for 300 second timeout as default * Cleanup old unused tests * Simplify how fetch utilizes timeouts from agent
- Loading branch information
Showing
4 changed files
with
49 additions
and
34 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,49 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
|
||
const { fetch, Agent } = require('../..') | ||
const { createServer } = require('http') | ||
const FakeTimers = require('@sinonjs/fake-timers') | ||
|
||
test('Fetch very long request, timeout overridden so no error', (t) => { | ||
const minutes = 6 | ||
const msToDelay = 1000 * 60 * minutes | ||
|
||
t.setTimeout(undefined) | ||
t.plan(1) | ||
|
||
const clock = FakeTimers.install() | ||
t.teardown(clock.uninstall.bind(clock)) | ||
|
||
const server = createServer((req, res) => { | ||
setTimeout(() => { | ||
res.end('hello') | ||
}, msToDelay) | ||
clock.tick(msToDelay + 1) | ||
}) | ||
t.teardown(server.close.bind(server)) | ||
|
||
server.listen(0, () => { | ||
fetch(`http://localhost:${server.address().port}`, { | ||
path: '/', | ||
method: 'GET', | ||
dispatcher: new Agent({ | ||
headersTimeout: 0, | ||
connectTimeout: 0, | ||
bodyTimeout: 0 | ||
}) | ||
}) | ||
.then((response) => response.text()) | ||
.then((response) => { | ||
t.equal('hello', response) | ||
t.end() | ||
}) | ||
.catch((err) => { | ||
// This should not happen, a timeout error should not occur | ||
t.error(err) | ||
}) | ||
|
||
clock.tick(msToDelay - 1) | ||
}) | ||
}) |
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