From b8e57ced78b2ffb4f495a9bc5a3063fb57482b08 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 2cf188abe5ffc9..8ba6c15aa49b40 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -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;