getSeenRequests never completing due to rule.requests never resolving promise.
See original GitHub issueI’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:
- Created 2 years ago
- Comments:17 (17 by maintainers)
Top GitHub Comments
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
stoppedgetSeenRequests
from resolving is now fixed?I’m going to assume this is now fixed and close this, but feel free to share more info if not.