From 26a5d9a66c81d24ca7275fe76c63e8e3e380bcbb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 4 Dec 2017 05:46:40 -0800 Subject: [PATCH] test: forbid `common.mustCall*()` in process exit handlers `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: https://github.com/nodejs/node/pull/17453 Reviewed-By: Anatoli Papirovski Reviewed-By: Colin Ihrig Reviewed-By: Khaidi Chu Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/common/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/common/index.js b/test/common/index.js index 164817fb0a8913..7e94bc766de369 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -506,6 +506,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;