node/test/parallel/test-beforeexit-event.js
CodeTheInternet 7b4c598b29 test: strictEqual in test-beforeexit-event.js
PR-URL: https://github.com/nodejs/node/pull/10004
Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-12-05 15:05:48 -05:00

43 lines
868 B
JavaScript

'use strict';
require('../common');
var assert = require('assert');
var net = require('net');
var revivals = 0;
var deaths = 0;
process.on('beforeExit', function() { deaths++; });
process.once('beforeExit', tryImmediate);
function tryImmediate() {
console.log('set immediate');
setImmediate(function() {
revivals++;
process.once('beforeExit', tryTimer);
});
}
function tryTimer() {
console.log('set a timeout');
setTimeout(function() {
console.log('timeout cb, do another once beforeExit');
revivals++;
process.once('beforeExit', tryListen);
}, 1);
}
function tryListen() {
console.log('create a server');
net.createServer()
.listen(0)
.on('listening', function() {
revivals++;
this.close();
});
}
process.on('exit', function() {
assert.strictEqual(4, deaths);
assert.strictEqual(3, revivals);
});