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.

getSeenRequests never completing due to rule.requests never resolving promise.

See original GitHub issue

I’ve got a mocked endpoint:

    const mockedEndpoint = mockServer.post("/id/endpoint").thenJson(200 , { total: 3 });

I can see with the logging it’s being added okay:

Handling request for /id/endpoint Request matched rule: Match requests making POSTs for /id/endpoint, and then respond with status 200, headers {“Content-Type”:“application/json”,“Content-Length”:“40”} and body “{“total”:3}”.

The endpoint is called in a browser test, and it does respond with the correct reply, within 6ms, not stuck pending.

Then I later check it’s been called with the correct info:

log.debug("Got mocked endpoint", mockedEndpoint);
const requests = await mockedEndpoint.getSeenRequests();

The problem is this times out. The promise never completes. I added some logging to ensure I’ve got the right endpoint:

Got mocked endpoint Mocked endpoint: Match requests making POSTs for /id/endpoint, and then respond with status 200, headers {“Content-Type”:“application/json”,“Content-Length”:“40”} and body “{“total”:3}”.

Then I added some logging to the library itself to check the requests promises:

    getSeenRequests() {
        // Wait for all completed running requests to have all their details available
        console.log(this.rule.requests);
        return Promise.all(this.rule.requests);
    }

Which reports the single expected request that’s stuck: [ Promise { <pending> } ]

I’ve no idea why this particular endpoint is hanging, it works with all the others (more complex ones with body and query matchers). The response does come through in the browser tests where I’m calling it. It responds with the correct reply, within 6ms. It’s just the call to getSeenRequests.

Have you seen this before? Is there anything that would case it to get stuck unresolved?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
pimterrycommented, Oct 12, 2021

Hey @hanvyj - I’ve just released 2.3.0, which includes your changes from #56, but also a few relevant fixes around getSeenRequests for a various cases where that could error and timeout unexpectedly.

These are good general fixes regardless, but I’m also hopeful that they might relate to your mystery issue here. When you get a minute at some point, can you update and see if the issue where thenJson stopped getSeenRequests from resolving is now fixed?

0reactions
pimterrycommented, Apr 22, 2022

I’m going to assume this is now fixed and close this, but feel free to share more info if not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

what happens when a Promise never resolves? - Stack Overflow
When the times/request resolve Node subtracts from the count. This count is how Node decides whether to exit at the end of the...
Read more >
Promise() constructor - JavaScript - MDN Web Docs
The Promise() constructor is primarily used to wrap functions that ... the promise will never be instantly resolved if a thenable is passed....
Read more >
Writing Promise-Using Specifications - W3C
When it will be impossible to complete the requested task: for example if the operation is accessUsersContacts() and the user denies permission, ...
Read more >
Promises chaining - The Modern JavaScript Tutorial
Promises provide a couple of recipes to do that. In this chapter we cover promise chaining. It looks like this: new Promise(function(resolve ......
Read more >
Fullstack React: Introduction to Promises
A promise only ever has one of three states at any given time: pending; fulfilled (resolved); rejected (error). A pending promise can only...
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