Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
test-net-connect-econnrefused: don't take forever to complete
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jun 12, 2012
1 parent b27a4cb commit 517cea3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/pummel/test-net-connect-econnrefused.js
Expand Up @@ -25,19 +25,25 @@ var common = require('../common');
var assert = require('assert');
var net = require('net');

var ROUNDS = 1024;
var ROUNDS = 5;
var ATTEMPTS_PER_ROUND = 200;
var rounds = 0;
var reqs = 0;

pummel();

function pummel() {
net.createConnection(common.PORT).on('error', function(err) {
assert.equal(err.code, 'ECONNREFUSED');
if (++rounds < ROUNDS) return pummel();
check();
});
reqs++;
console.log('Round', rounds, '/', ROUNDS);

for (var pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) {
net.createConnection(common.PORT).on('error', function(err) {
assert.equal(err.code, 'ECONNREFUSED');
if (--pending > 0) return;
if (++rounds < ROUNDS) return pummel();
check();
});
reqs++;
}
}

function check() {
Expand All @@ -53,6 +59,6 @@ var check_called = false;

process.on('exit', function() {
assert.equal(rounds, ROUNDS);
assert.equal(reqs, ROUNDS);
assert.equal(reqs, ROUNDS * ATTEMPTS_PER_ROUND);
assert(check_called);
});

0 comments on commit 517cea3

Please sign in to comment.