mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
test: refactor test-beforeexit-event
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: https://github.com/nodejs/node/pull/10121 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
1 parent
314b04d2d9
commit
3686687cd2
1 file changed
+12
-28
@@ -1,42 +1,26 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
var assert = require('assert');
|
||||
var net = require('net');
|
||||
var revivals = 0;
|
||||
var deaths = 0;
|
||||
const common = require('../common');
|
||||
const net = require('net');
|
||||
|
||||
process.on('beforeExit', function() { deaths++; });
|
||||
|
||||
process.once('beforeExit', tryImmediate);
|
||||
process.once('beforeExit', common.mustCall(tryImmediate));
|
||||
|
||||
function tryImmediate() {
|
||||
console.log('set immediate');
|
||||
setImmediate(function() {
|
||||
revivals++;
|
||||
process.once('beforeExit', tryTimer);
|
||||
});
|
||||
setImmediate(common.mustCall(() => {
|
||||
process.once('beforeExit', common.mustCall(tryTimer));
|
||||
}));
|
||||
}
|
||||
|
||||
function tryTimer() {
|
||||
console.log('set a timeout');
|
||||
setTimeout(function() {
|
||||
console.log('timeout cb, do another once beforeExit');
|
||||
revivals++;
|
||||
process.once('beforeExit', tryListen);
|
||||
}, 1);
|
||||
setTimeout(common.mustCall(() => {
|
||||
process.once('beforeExit', common.mustCall(tryListen));
|
||||
}), 1);
|
||||
}
|
||||
|
||||
function tryListen() {
|
||||
console.log('create a server');
|
||||
net.createServer()
|
||||
.listen(0)
|
||||
.on('listening', function() {
|
||||
revivals++;
|
||||
.on('listening', common.mustCall(function() {
|
||||
this.close();
|
||||
});
|
||||
process.on('beforeExit', common.mustCall(() => {}));
|
||||
}));
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.strictEqual(4, deaths);
|
||||
assert.strictEqual(3, revivals);
|
||||
});
|
||||
Reference in new issue
Block a user