When I run https://github.com/request/request against an actual HTTP server that delays closing the HTTP request after sending headers, I get a timeout or socket timeout. When I run it against nock configured to perform a delayBody with the same time, I do not get a timeout or socket timeout.
Take a look at https://github.com/jeffcharles/nock-timeout-testcase for an executable example. Running it on my machine results in:
Request sent back error: Error: ESOCKETTIMEDOUT
Nock should have failed with timeout but didn't
How can I configure Nock to timeout the socket given headers being sent back but the response not having been ended?
+1
i believe i tried same thing, following code will return then block should not execute: Hello from Google! while i would expect ETIMEDOUT
mocha test/force-req-timeout.test.js --timeout=10000
'use strict'
const chai = require('chai')
const expect = chai.expect
const nock = require('nock')
const rp = require('request-promise')
describe('force request timeout with nock', () => {
it('should return ETIMEDOUT', (done) => {
nock('http://www.google.com')
.get('/')
.delay(8000)
.reply(200, 'Hello from Google!')
rp({
url: 'http://www.google.com',
timeout: 5000
})
.then((data) => {
console.log('then block should not execute: ', data)
...
})
.catch((err) => {
expect(err.cause.code).to.equal('ETIMEDOUT')
...
})
})
})
http://stackoverflow.com/questions/36533807/how-to-etimedout-with-nock-and-request-library
Definitely an issue. Until this is addressed, for properly testing timeouts with the request library, you should use at least these 3 error scenarios with replyWithError:
nock(...)...
.replyWithError({code: 'ETIMEDOUT', connect: true});
nock(...)...
.replyWithError({code: 'ETIMEDOUT', connect: false});
nock(...)...
.replyWithError({code: 'ESOCKETTIMEDOUT'});
Just noticed this as well. Any news on it? @pgte ?
馃憢 @hugoduraes Pedro is not maintaining nock any longer, I鈥檓 trying my best to help out (and onboard new maintainers hint hint). I鈥檓 on vacation right now, I can look into it after April 22. If anyone would like to send a PR, happy to review it after unless someone beats me to it :)
Trying to look at this but I'm not understanding what's wrong. Has anyone looked at the source code and tried to find the issue?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it鈥檚 related. Thank you!
Most helpful comment
+1
i believe i tried same thing, following code will return
then block should not execute: Hello from Google!while i would expectETIMEDOUTmocha test/force-req-timeout.test.js --timeout=10000http://stackoverflow.com/questions/36533807/how-to-etimedout-with-nock-and-request-library