From f03c77436003f77f43ffe0f1803d73e50544570b Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Mon, 25 Jul 2022 00:59:25 +0200 Subject: [PATCH] test: work scheduled in process.nextTick can keep the event loop alive PR-URL: https://github.com/nodejs/node/pull/43787 Reviewed-By: Antoine du Hamel Reviewed-By: Ujjwal Sharma --- test/parallel/test-process-beforeexit.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index 7b7ba48f7d8cb4..e04b756cade8bc 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -59,12 +59,21 @@ function tryRepeatedTimer() { if (++n < N) setTimeout(repeatedTimer, 1); else // n == N - process.once('beforeExit', common.mustCall(tryNextTick)); + process.once('beforeExit', common.mustCall(tryNextTickSetImmediate)); }, N); setTimeout(repeatedTimer, 1); } // Test if the callback of `process.nextTick` can be invoked. +function tryNextTickSetImmediate() { + process.nextTick(common.mustCall(function() { + setImmediate(common.mustCall(() => { + process.once('beforeExit', common.mustCall(tryNextTick)); + })); + })); +} + +// Test that `process.nextTick` won't keep the event loop running by itself. function tryNextTick() { process.nextTick(common.mustCall(function() { process.once('beforeExit', common.mustNotCall());