Skip to content

Commit 94204f7

Browse files
ttzztztztargos
authored andcommitted
test: process.nextTick for before exit
PR-URL: #37012 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3722c15 commit 94204f7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/parallel/test-process-beforeexit.js

+12
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,24 @@ function tryListen() {
4949
// Test that a function invoked from the beforeExit handler can use a timer
5050
// to keep the event loop open, which can use another timer to keep the event
5151
// loop open, etc.
52+
//
53+
// After N times, call function `tryNextTick` to test behaviors of the
54+
// `process.nextTick`.
5255
function tryRepeatedTimer() {
5356
const N = 5;
5457
let n = 0;
5558
const repeatedTimer = common.mustCall(function() {
5659
if (++n < N)
5760
setTimeout(repeatedTimer, 1);
61+
else // n == N
62+
process.once('beforeExit', common.mustCall(tryNextTick));
5863
}, N);
5964
setTimeout(repeatedTimer, 1);
6065
}
66+
67+
// Test if the callback of `process.nextTick` can be invoked.
68+
function tryNextTick() {
69+
process.nextTick(common.mustCall(function() {
70+
process.once('beforeExit', common.mustNotCall());
71+
}));
72+
}

0 commit comments

Comments
 (0)