From f4c0e6cd6a2d387cf39ed37a7baef91d7353882d Mon Sep 17 00:00:00 2001 From: ttzztztz Date: Thu, 21 Jan 2021 11:07:29 +0800 Subject: [PATCH 1/6] test: process.nextTick for before exit --- test/parallel/test-process-beforeexit.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index 215e73dc0650f3..69b3ecdd7572a5 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -55,6 +55,14 @@ function tryRepeatedTimer() { const repeatedTimer = common.mustCall(function() { if (++n < N) setTimeout(repeatedTimer, 1); + else // n == N + process.once('beforeExit', common.mustCall(tryNextTick)); }, N); setTimeout(repeatedTimer, 1); } + +function tryNextTick() { + process.nextTick(common.mustCall(function() { + process.once('beforeExit', common.mustNotCall(function() {})); + })); +} From d057220ed5e0417f3b51913ffd660b027c925ae9 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Sat, 23 Jan 2021 08:53:38 +0800 Subject: [PATCH 2/6] Update test/parallel/test-process-beforeexit.js Co-authored-by: Luigi Pinca --- test/parallel/test-process-beforeexit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index 69b3ecdd7572a5..777570f6404fcd 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -63,6 +63,6 @@ function tryRepeatedTimer() { function tryNextTick() { process.nextTick(common.mustCall(function() { - process.once('beforeExit', common.mustNotCall(function() {})); + process.once('beforeExit', common.mustNotCall()); })); } From c19b457e0ef54d884aceaad0166ee6fb6cb14e1e Mon Sep 17 00:00:00 2001 From: Rabbit Date: Mon, 25 Jan 2021 15:04:49 +0800 Subject: [PATCH 3/6] chore: comments for the extra unit test --- test/parallel/test-process-beforeexit.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index 777570f6404fcd..90b13596436665 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -49,6 +49,8 @@ function tryListen() { // Test that a function invoked from the beforeExit handler can use a timer // to keep the event loop open, which can use another timer to keep the event // loop open, etc. +// +// After N times, call function tryNextTick to test behaviors of process.nextTick function tryRepeatedTimer() { const N = 5; let n = 0; @@ -61,6 +63,7 @@ function tryRepeatedTimer() { setTimeout(repeatedTimer, 1); } +// Test if the callback of process.nextTick can be invoked function tryNextTick() { process.nextTick(common.mustCall(function() { process.once('beforeExit', common.mustNotCall()); From 894f133989817a413e653971d3c8097b146d3abe Mon Sep 17 00:00:00 2001 From: Rabbit Date: Mon, 25 Jan 2021 15:50:43 +0800 Subject: [PATCH 4/6] fix: linter issues --- 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 90b13596436665..b11f3d0f184a9c 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -49,8 +49,8 @@ function tryListen() { // Test that a function invoked from the beforeExit handler can use a timer // to keep the event loop open, which can use another timer to keep the event // loop open, etc. -// -// After N times, call function tryNextTick to test behaviors of process.nextTick +// +// After N times, call function tryNextTick to test behaviors of nextTick function tryRepeatedTimer() { const N = 5; let n = 0; From f6d0643d9d18abd39bad2a26d38dea1e2873c297 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Mon, 25 Jan 2021 19:01:22 +0800 Subject: [PATCH 5/6] chore: comment --- test/parallel/test-process-beforeexit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js index b11f3d0f184a9c..e28989ea463b87 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -50,7 +50,8 @@ function tryListen() { // to keep the event loop open, which can use another timer to keep the event // loop open, etc. // -// After N times, call function tryNextTick to test behaviors of nextTick +// After N times, call function `tryNextTick` to test behaviors of the +// `process.nextTick` function tryRepeatedTimer() { const N = 5; let n = 0; @@ -63,7 +64,7 @@ function tryRepeatedTimer() { setTimeout(repeatedTimer, 1); } -// Test if the callback of process.nextTick can be invoked +// Test if the callback of `process.nextTick` can be invoked function tryNextTick() { process.nextTick(common.mustCall(function() { process.once('beforeExit', common.mustNotCall()); From 6fbf936551e751335721821de9093451c8d701f2 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Mon, 25 Jan 2021 19:49:57 +0800 Subject: [PATCH 6/6] comment: nit --- 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 e28989ea463b87..7b7ba48f7d8cb4 100644 --- a/test/parallel/test-process-beforeexit.js +++ b/test/parallel/test-process-beforeexit.js @@ -51,7 +51,7 @@ function tryListen() { // loop open, etc. // // After N times, call function `tryNextTick` to test behaviors of the -// `process.nextTick` +// `process.nextTick`. function tryRepeatedTimer() { const N = 5; let n = 0; @@ -64,7 +64,7 @@ function tryRepeatedTimer() { setTimeout(repeatedTimer, 1); } -// Test if the callback of `process.nextTick` can be invoked +// Test if the callback of `process.nextTick` can be invoked. function tryNextTick() { process.nextTick(common.mustCall(function() { process.once('beforeExit', common.mustNotCall());