From 517cea3636b7a101799214d71ddb98eaea8e0198 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 12 Jun 2012 02:22:30 +0200 Subject: [PATCH] test-net-connect-econnrefused: don't take forever to complete --- test/pummel/test-net-connect-econnrefused.js | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/pummel/test-net-connect-econnrefused.js b/test/pummel/test-net-connect-econnrefused.js index a6fed70dbe0..bb3ef5945e3 100644 --- a/test/pummel/test-net-connect-econnrefused.js +++ b/test/pummel/test-net-connect-econnrefused.js @@ -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() { @@ -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); });