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 <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Dec 12, 2017
1 parent 5277156 commit b8e57ce
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 b8e57ce

Please sign in to comment.