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:
parent
8066215e5d
commit
d2c96af152
@ -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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user