mirror of https://github.com/nodejs/node.git
test-net-connect-econnrefused: don't take forever to complete
parent
b27a4cbe2a
commit
517cea3636
|
@ -25,19 +25,25 @@ var common = require('../common');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
|
|
||||||
var ROUNDS = 1024;
|
var ROUNDS = 5;
|
||||||
|
var ATTEMPTS_PER_ROUND = 200;
|
||||||
var rounds = 0;
|
var rounds = 0;
|
||||||
var reqs = 0;
|
var reqs = 0;
|
||||||
|
|
||||||
pummel();
|
pummel();
|
||||||
|
|
||||||
function pummel() {
|
function pummel() {
|
||||||
net.createConnection(common.PORT).on('error', function(err) {
|
console.log('Round', rounds, '/', ROUNDS);
|
||||||
assert.equal(err.code, 'ECONNREFUSED');
|
|
||||||
if (++rounds < ROUNDS) return pummel();
|
for (var pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) {
|
||||||
check();
|
net.createConnection(common.PORT).on('error', function(err) {
|
||||||
});
|
assert.equal(err.code, 'ECONNREFUSED');
|
||||||
reqs++;
|
if (--pending > 0) return;
|
||||||
|
if (++rounds < ROUNDS) return pummel();
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
reqs++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
|
@ -53,6 +59,6 @@ var check_called = false;
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
assert.equal(rounds, ROUNDS);
|
assert.equal(rounds, ROUNDS);
|
||||||
assert.equal(reqs, ROUNDS);
|
assert.equal(reqs, ROUNDS * ATTEMPTS_PER_ROUND);
|
||||||
assert(check_called);
|
assert(check_called);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue