Skip to content

Commit

Permalink
test: forbid common.mustCall*() in process exit handlers
Browse files Browse the repository at this point in the history
`common.mustCall()` and `common.mustCallAtLeast()` need to be called
before process exit handlers to work because checks are done inside a
process exit handler. Detect if being used inside a process exit handler
and throw.

PR-URL: #17453
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and MylesBorins committed Dec 12, 2017
1 parent 85e6271 commit 0ade488
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ exports.mustCallAtLeast = function(fn, minimum) {
};

function _mustCallInner(fn, criteria = 1, field) {
if (process._exiting)
throw new Error('Cannot use common.mustCall*() in process exit handler');
if (typeof fn === 'number') {
criteria = fn;
fn = noop;
Expand Down

0 comments on commit 0ade488

Please sign in to comment.