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>
This commit is contained in:
Rich Trott authored and Italo A. Casas committed 2017-01-30 12:08:34 -05:00
1 parent 33851d1e2c
commit db7b27abb9
2 files changed
+14 -15

No files matched your search

-14
View File
@@ -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.
});
@@ -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);
}