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.

Repeated interception when requests are made within Promise.all()

See original GitHub issue

What is the expected behavior?

Interceptors are not persisted by default, which means that only one request will be matched and others should throw an error No match for request.

What is the actual behavior?

If requests are made within Promise.all() and registered interceptor is defined with reply with callback, it handles multiple requests. See the demonstrations below.

How to reproduce the issue

Issue reproduced where 3 requests are successful: Interceptor with reply callback Correct behavior with error thrown: Interceptor without reply callback

Does the bug have a test case?

I expect it does not have.

Versions

Software Version(s)
Nock 12.0.1
Node 10

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mastermattcommented, Jun 30, 2020

Given the fixes to the timing and event handling for v13, I’m not surprised unfortunately.

To fix this bug, we need the call to Interceptor.markConsumed to happen in the same microtask execution as the Interceptor matching that occurs in startPlayback. Currently, there is a setImmediate and an abort check between the two (ref).

I think we can simply move the call to markConsumed out of start and have it called just before the “finish” event is called on the request, here. I’ve started to write some tests, but I need to the day-job thing now. (I’m using this comment as notes to myself, sorry for any ramblings…) Off the top of my head, I assume moving markConsumed will work. The effect it will have is that request that is immediately aborted will consume an Interceptor, whereas before it didn’t until a full cycle of the event loop. But, I might argue this is also a bug anyway.

0reactions
gurpreetatwalcommented, Aug 5, 2020

@mastermatt thank you for the quick fix 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise.all() - JavaScript - MDN Web Docs
The Promise.all() method is one of the promise concurrency methods. It can be useful for aggregating the results of multiple promises.
Read more >
How to use JavaScript Promise.all with real-life code example
JavaScript's Promise. all() method takes in a parameter of iterable promises runs them concurrently then returns a single Promise that resolves ...
Read more >
Axios/Vue - Prevent axios.all() to keep executing
Promise.all is rejected if any of the elements are rejected. For example, if you pass in four promises that resolve after a timeout...
Read more >
Aggregate Multiple API Requests with Promise.all()
Promise. all() takes an iterable (an array) of promises. It returns an array containing each promise resolution in the same order.
Read more >
Complete Guide to Axios HTTP Client - Reflectoring
Axios is also a promise-based HTTP client that can be used in plain ... we are making requests to two APIs using the...
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