diff options
author | Rich Trott <rtrott@gmail.com> | 2017-01-02 17:23:31 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-01-05 16:55:43 -0800 |
commit | d2c96af152f0213375612b7fd4f52cb521389935 (patch) | |
tree | 0bbf66e995ab21039a07993afeb9bcd76b56f9d8 | |
parent | 8066215e5d2c37b36eb48248ec74324387b9012c (diff) | |
download | node-new-d2c96af152f0213375612b7fd4f52cb521389935.tar.gz |
test: refactor beforeExit tests
Combine and rename tests for the `beforeExit` event on `process`.
The naming now more closely follows the de facto conventions of the
project.
The two tests were very similar and do not seem to benefit from being
separate.
PR-URL: https://github.com/nodejs/node/pull/10581
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
-rw-r--r-- | test/parallel/test-process-before-exit.js | 14 | ||||
-rw-r--r-- | test/parallel/test-process-beforeexit.js (renamed from test/parallel/test-beforeexit-event.js) | 15 |
2 files changed, 14 insertions, 15 deletions
diff --git a/test/parallel/test-process-before-exit.js b/test/parallel/test-process-before-exit.js deleted file mode 100644 index 01590de0fc..0000000000 --- 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 index ef94da76af..4557628c42 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); +} |