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 /test/parallel/test-process-beforeexit.js | |
parent | 8066215e5d2c37b36eb48248ec74324387b9012c (diff) | |
download | android-node-v8-d2c96af152f0213375612b7fd4f52cb521389935.tar.gz android-node-v8-d2c96af152f0213375612b7fd4f52cb521389935.tar.bz2 android-node-v8-d2c96af152f0213375612b7fd4f52cb521389935.zip |
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>
Diffstat (limited to 'test/parallel/test-process-beforeexit.js')
-rw-r--r-- | test/parallel/test-process-beforeexit.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/parallel/test-process-beforeexit.js b/test/parallel/test-process-beforeexit.js new file mode 100644 index 0000000000..4557628c42 --- /dev/null +++ b/test/parallel/test-process-beforeexit.js @@ -0,0 +1,39 @@ +'use strict'; +const common = require('../common'); +const net = require('net'); + +process.once('beforeExit', common.mustCall(tryImmediate)); + +function tryImmediate() { + setImmediate(common.mustCall(() => { + process.once('beforeExit', common.mustCall(tryTimer)); + })); +} + +function tryTimer() { + setTimeout(common.mustCall(() => { + process.once('beforeExit', common.mustCall(tryListen)); + }), 1); +} + +function tryListen() { + net.createServer() + .listen(0) + .on('listening', common.mustCall(function() { + this.close(); + 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); +} |