diff --git a/test/parallel/test-process-before-exit.js b/test/parallel/test-process-before-exit.js deleted file mode 100644 index 01590de0fcf844..00000000000000 --- a/test/parallel/test-process-before-exit.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; -require('../common'); -const assert = require('assert'); - -var N = 5; -var n = 0; - -function f() { - if (++n < N) setTimeout(f, 5); -} -process.on('beforeExit', f); -process.on('exit', function() { - assert.equal(n, N + 1); // The sixth time we let it through. -}); diff --git a/test/parallel/test-beforeexit-event.js b/test/parallel/test-process-beforeexit.js similarity index 54% rename from test/parallel/test-beforeexit-event.js rename to test/parallel/test-process-beforeexit.js index ef94da76af3883..4557628c42b611 100644 --- a/test/parallel/test-beforeexit-event.js +++ b/test/parallel/test-process-beforeexit.js @@ -21,6 +21,19 @@ function tryListen() { .listen(0) .on('listening', common.mustCall(function() { this.close(); - process.on('beforeExit', common.mustCall(() => {})); + process.once('beforeExit', common.mustCall(tryRepeatedTimer)); })); } + +// 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. +function tryRepeatedTimer() { + const N = 5; + let n = 0; + const repeatedTimer = common.mustCall(function() { + if (++n < N) + setTimeout(repeatedTimer, 1); + }, N); + setTimeout(repeatedTimer, 1); +}