-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
test: add setTimeout
tests
#558
test: add setTimeout
tests
#558
Conversation
@mikicho, I think you should know about the difference I outlined above. See if Nock understands those two different timeouts and treats them the same. It's rather tricky and undocumented, and I wouldn't be surprised if it didn't. |
I also suspect that |
e52851c
into
feat/yet-another-socket-interceptor
Nock is aware of these two, and it actually uses this value for throwing a timeout error immediately if the timeout is bigger than what is defined in the interceptor. P.S: when I tried to implement this for the |
Interceptors do not decide that for you so they shouldn't do anything on top of what Node.js does. Node.js doesn't do anything to the request, not even destroys it. It only emits the
Yep, I remember that! |
Nock does not change Node.js behavior here:
Users still can use fake timers instead, but Nock give this OOTB which is nice. |
Timeout was supported as-is, I've only added automated tests.
Important
http.request(u, { timeout: n })
andhttp.request(u).setTimeout(n)
are NOT the same! The first acts on thehttp.Agent
level, adding timeout to everynet.Socket
once it's created. The second, however, ignores the agent and sets the timeout on the socket once it emits the "connect" event. The first takes the connection time into account, the second doesn't.I've opened a pull request to the Node.js docs (nodejs/node#52576) to help emphasize this difference.
In the context of Interceptors, this difference is important because we can reproduce
http.request(u, { timeout: n })
by making the request listener take more time than the specified timeout, but thehttp.request(u).setTimeout(n)
must receive either a mocked or bypassed response headers before it's even added (socket connect emitted).Also adds a
this.destroyed
check inpassthrough()
andrespondWith()
so they'd have no effect if the socket has been destroyed (e.g. aborted or timed out).