mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
This helps to prevent issues where a failed test can keep a bound socket open long enough to cause other tests to fail with EADDRINUSE because the same port number is used. PR-URL: https://github.com/nodejs/node/pull/7045 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
43 lines
856 B
JavaScript
43 lines
856 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.equal(4, deaths);
|
|
assert.equal(3, revivals);
|
|
});
|