Skip to content
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

Testing ECONNREFUSED #410

Closed
redben opened this issue Nov 18, 2015 · 13 comments
Closed

Testing ECONNREFUSED #410

redben opened this issue Nov 18, 2015 · 13 comments

Comments

@redben
Copy link

redben commented Nov 18, 2015

When using nock one can test server http errors.
Is there any way to test request errors like ENOTFOUND or ECONNREFUSED using nock ?

@pgte
Copy link
Member

pgte commented Nov 19, 2015

You could use .replyWithError(err) to simulate that. You would have to create a mock error object with the .code attribute, etc.

I'm keeping this issue open, since I think nock could provide an easier way to reply with those types of errors.

@filipedeschamps
Copy link

@pgte like this:

            nock('http://ww.cantconnecttothis.addres/')
                .get('feed')
                .replyWithError({ 
                    code: 'ENOTFOUND',
                    errno: 'ENOTFOUND',
                    syscall: 'getaddrinfo',
                    hostname: 'www.skdhsdk.com'
                });

Doesn't seems to work.

@kevinburkeshyp
Copy link

I wrote a project that starts servers for this in Python: http://github.com/kevinburke/hamms

The easiest way is simply to connect to a localhost port where nothing is listening. ETIMEDOUT you can generally use 10.255.255.1 and set a timeout, though I guess nock can just throw errors on its own if you want.

@1999
Copy link

1999 commented Dec 23, 2015

There's a problem with replyWithError: it doesn't support .delay option. I mean that mocked requests with replyWithError reply immediately with an error regardless of the delay value.

afaik this is also not tested: https://github.com/pgte/nock/blob/049799c35f388d7fbf0a614e1f956a8b5eb7f63d/tests/test_intercept.js#L2863

@pgte
Copy link
Member

pgte commented Dec 23, 2015

@1999 could you please create a separate issue for this?

@pgte
Copy link
Member

pgte commented Dec 23, 2015

@redben what's the status of this?

@pgte
Copy link
Member

pgte commented Dec 23, 2015

@filipedeschamps could you please elaborate?

@1999
Copy link

1999 commented Dec 23, 2015

@pgte I can also PR this if you think that's unexpected behaviour

@pgte
Copy link
Member

pgte commented Dec 23, 2015

@1999 PR is welcome :)

@1999
Copy link

1999 commented Dec 23, 2015

@pgte sorry, I've just re-run tests and acknowledged that everything is okay. The problem was in old nock version used in webdriverio.

@pgte
Copy link
Member

pgte commented Dec 24, 2015

I'm closing this for lack of feedback. Please reopen if you have more info.

@pgte pgte closed this as completed Dec 24, 2015
@redben
Copy link
Author

redben commented Jan 1, 2016

Sorry didn't pay attention to notifications.

  • For ECONNREFUSED, I ended up disabling nock and passing a url to the unit under test with a port that I know is closed (http://localhost:{closed-port} )
  • For ENOTFOUND i set the url to a random hostname.

So basically these two can be tested without nock. Thanks anyway !

@lock
Copy link

lock bot commented Sep 13, 2018

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’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants