question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for simulating errors

See original GitHub issue

Nock is excellent! Something that would make it even excellenter is if nock could be used to simulate connection level errors:

nock("http://api.example.com")
  .get("/some/path")
  .failWith(new Error("socket hang up"));

Especially since these can be otherwise cumbersome to test. Keep up the good work!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
srkimircommented, Jan 4, 2017

In the end i solved it with something like:

nock('http://www.google.com')
  .get('/')
  .replyWithError({code: 'ETIMEDOUT'})

Which looks clean, it does not involve delay and stuff, and as it seems to me it is enough to simulate ETIMEDOUT having in mind that im using request-promise lib where i’m checking for ETIMEDOUT like: if (err.error && err.error.code === 'ETIMEDOUT')

Same can be applied for ENOTFOUND, ECONNRESET, ECONNREFUSED...

2reactions
eokoneyocommented, Jun 5, 2017

Hi Guys I had this same issue with superagent when trying to test timeout, took about a whole weekend to put it together that it is because superagent always retries requests by default, in fact deafult is 3 [http://visionmedia.github.io/superagent/#retrying-requests](see here) , so on the second retry nock has no url to match thats why you get

{ Error: Nock: No match for request {
 "method": "POST",
 "url": "http://someurl.com/",
 "body": "some_string"
}
   at end (/Users/eyo.okon/Sites/node-graphql-client/node_modules/nock/lib/request_overrider.js:260:17)
   at OverriddenClientRequest.RequestOverrider.req.end (/Users/eyo.okon/Sites/node-graphql-client/node_modules/nock/lib/request_overrider.js:160:7)
   at Request._end (/Users/eyo.okon/Sites/node-graphql-client/node_modules/superagent/lib/node/index.js:961:9)
   at RequestBase._retry (/Users/eyo.okon/Sites/node-graphql-client/node_modules/superagent/lib/request-base.js:176:15)
   at Request.callback (/Users/eyo.okon/Sites/node-graphql-client/node_modules/superagent/lib/node/index.js:657:17)
   at RequestBase._timeoutError (/Users/eyo.okon/Sites/node-graphql-client/node_modules/superagent/lib/request-base.js:573:8)
   at Timeout.<anonymous> (/Users/eyo.okon/Sites/node-graphql-client/node_modules/superagent/lib/request-base.js:582:12)
   at ontimeout (timers.js:365:14)
   at tryOnTimeout (timers.js:237:5)   at Timer.listOnTimeout (timers.js:207:5) status: 404, statusCode: 404, response: undefined, retries: 1 }

on setting retry to 0 one gets the correct error, and test passes… 🕺🏾 Hopefully this helps someone

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simulation Errors
Simulation errors usually cause the simulation to crash. Table 7 below lists common types of these errors and gives examples for each type....
Read more >
Troubleshooting Simulation Errors - MATLAB & Simulink
Simscape™ simulations can stop before completion with one or more error messages. This section discusses generic error types and error-fixing strategies. You ...
Read more >
The importance of simulated errors in observing system ...
Observing System Simulation Experiments (OSSEs) for numerical weather prediction rely on simulated observations that should include simulated observation errors ...
Read more >
Simulating faults in API behavior - WireMock
This is useful for simulating a slow network and testing deterministic timeouts. Use #withChunkedDribbleDelay on the stub to pass in the desired chunked ......
Read more >
Time Error Simulation Software | SiTime
Time error analysis using real-time data is a complex and lengthy process that can take from weeks to months to perform. To help...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found