fix(mock): settle the dispatch when an async reply data function rejects - #5762
Open
pacocartones wants to merge 1 commit into
Open
fix(mock): settle the dispatch when an async reply data function rejects#5762pacocartones wants to merge 1 commit into
pacocartones wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5762 +/- ##
==========================================
- Coverage 93.50% 93.49% -0.01%
==========================================
Files 110 110
Lines 39072 39084 +12
==========================================
+ Hits 36534 36543 +9
- Misses 2538 2541 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The data-function form of .reply(statusCode, data) already awaits a returned promise and re-runs handleReply with the resolved body, but the promise had no rejection handler. When the data function rejects, no terminal onResponse* callback fires: the dispatched request never settles (hang) and the rejection surfaces as an unhandledRejection. Add a rejection arm that mirrors the reply-options-callback path: respect an in-flight abort, then delete the mock dispatch and emit a single onResponseError on the controller. Signed-off-by: Paco Cartones <pacocartones@users.noreply.github.com>
pacocartones
force-pushed
the
fix/mock-async-reply-reject
branch
from
September 4, 2026 02:14
da38bce to
67a405b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
MockPool/MockAgent.reply(statusCode, dataFn)supports an async data function — the returned promise is already awaited inhandleReply, and it's exercised in the existing suite (test/mock-agent.js:578,:3487). But that awaited promise had only a fulfilment handler: if the data function rejects, noonResponse*callback ever fires, so the dispatched request never settles (hang) and the rejection escapes as anunhandledRejection.Fix
Add the rejection arm, mirroring the file's own conventions — the sibling reply-options-callback path already handles both fulfil and reject, and the sync path re-checks
aborted:The request now rejects with the error, exactly one terminal callback, no unhandled rejection. Sync/options paths are untouched.
Test
test/mock-async-reply-reject.js:.reply(200, async () => { throw boom })then a request, with a timeout guard and anunhandledRejectionlistener. RED onmain(unhandled rejection; request never settles). GREEN with the fix (rejects withboom, data fn called once, no unhandled rejection).