node/test/parallel/test-beforeexit-event.js
Roman Reiss 647861befb test: fix issues for space-in-parens ESLint rule
PR-URL: https://github.com/nodejs/node/pull/4753
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-01-19 04:09:39 +01:00

43 lines
879 B
JavaScript

'use strict';
var assert = require('assert');
var net = require('net');
var common = require('../common');
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(common.PORT)
.on('listening', function() {
revivals++;
this.close();
});
}
process.on('exit', function() {
assert.equal(4, deaths);
assert.equal(3, revivals);
});