From 6bc38d8b6271420e1010ad63ca38c85c4f685452 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 12 Jul 2022 01:05:04 +0200 Subject: [PATCH 1/3] test: work scheduled in process.nextTick can keep the event loop alive --- test/parallel/test-process-beforeexit.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index 7b7ba48f7d8cb4..3b53f670c2a10c 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -59,13 +59,22 @@ function tryRepeatedTimer() { if (++n < N) setTimeout(repeatedTimer, 1); else // n == N - process.once('beforeExit', common.mustCall(tryNextTick)); + process.once('beforeExit', common.mustCall(tryNextTick1)); }, N); setTimeout(repeatedTimer, 1); } // Test if the callback of `process.nextTick` can be invoked. -function tryNextTick() { +function tryNextTick1() { + process.nextTick(common.mustCall(function() { + setTimeout(common.mustCall(() => { + process.once('beforeExit', common.mustCall(tryNextTick2)); + }), 0); + })); +} + +// Test that `process.nextTick` won't keep the event loop running by itself. +function tryNextTick2() { process.nextTick(common.mustCall(function() { process.once('beforeExit', common.mustNotCall()); })); From 60bdf1829ef37596a082a9fa34e4240af214ee4a Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 12 Jul 2022 11:07:38 +0200 Subject: [PATCH 2/3] Update test/parallel/test-process-beforeexit.js Co-authored-by: Antoine du Hamel --- test/parallel/test-process-beforeexit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index 3b53f670c2a10c..5386318e63891a 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -67,9 +67,9 @@ function tryRepeatedTimer() { // Test if the callback of `process.nextTick` can be invoked. function tryNextTick1() { process.nextTick(common.mustCall(function() { - setTimeout(common.mustCall(() => { + setImmediate(common.mustCall(() => { process.once('beforeExit', common.mustCall(tryNextTick2)); - }), 0); + })); })); } From a38e02be177ef266290aead8beea87b73f4760dd Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 12 Jul 2022 11:45:27 +0200 Subject: [PATCH 3/3] Review suggestions --- test/parallel/test-process-beforeexit.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index 5386318e63891a..e04b756cade8bc 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -59,22 +59,22 @@ function tryRepeatedTimer() { if (++n < N) setTimeout(repeatedTimer, 1); else // n == N - process.once('beforeExit', common.mustCall(tryNextTick1)); + process.once('beforeExit', common.mustCall(tryNextTickSetImmediate)); }, N); setTimeout(repeatedTimer, 1); } // Test if the callback of `process.nextTick` can be invoked. -function tryNextTick1() { +function tryNextTickSetImmediate() { process.nextTick(common.mustCall(function() { setImmediate(common.mustCall(() => { - process.once('beforeExit', common.mustCall(tryNextTick2)); + process.once('beforeExit', common.mustCall(tryNextTick)); })); })); } // Test that `process.nextTick` won't keep the event loop running by itself. -function tryNextTick2() { +function tryNextTick() { process.nextTick(common.mustCall(function() { process.once('beforeExit', common.mustNotCall()); }));