2017-01-03 22:16:48 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2019-01-14 05:35:52 +01:00
|
|
|
// Verify that connect reqs are properly cleaned up.
|
2012-04-30 00:58:15 +02:00
|
|
|
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2012-04-30 00:58:15 +02:00
|
|
|
|
2019-01-14 05:35:52 +01:00
|
|
|
const ROUNDS = 5;
|
|
|
|
const ATTEMPTS_PER_ROUND = 50;
|
2017-01-08 14:19:00 +01:00
|
|
|
let rounds = 1;
|
|
|
|
let reqs = 0;
|
2012-04-30 00:58:15 +02:00
|
|
|
|
|
|
|
pummel();
|
|
|
|
|
|
|
|
function pummel() {
|
2017-01-08 14:19:00 +01:00
|
|
|
let pending;
|
|
|
|
for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) {
|
2012-06-12 02:22:30 +02:00
|
|
|
net.createConnection(common.PORT).on('error', function(err) {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(err.code, 'ECONNREFUSED');
|
2012-06-12 02:22:30 +02:00
|
|
|
if (--pending > 0) return;
|
2016-08-17 06:11:22 +02:00
|
|
|
if (rounds === ROUNDS) return check();
|
2012-08-09 01:02:47 +02:00
|
|
|
rounds++;
|
|
|
|
pummel();
|
2012-06-12 02:22:30 +02:00
|
|
|
});
|
|
|
|
reqs++;
|
|
|
|
}
|
2012-04-30 00:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function check() {
|
2012-08-09 01:02:47 +02:00
|
|
|
setTimeout(function() {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(process._getActiveRequests().length, 0);
|
2019-01-10 23:04:52 +01:00
|
|
|
const activeHandles = process._getActiveHandles();
|
|
|
|
assert.ok(activeHandles.every((val) => val.constructor.name !== 'Socket'));
|
2012-08-09 01:02:47 +02:00
|
|
|
check_called = true;
|
|
|
|
}, 0);
|
2012-04-30 00:58:15 +02:00
|
|
|
}
|
2017-01-08 14:19:00 +01:00
|
|
|
let check_called = false;
|
2012-04-30 00:58:15 +02:00
|
|
|
|
|
|
|
process.on('exit', function() {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(rounds, ROUNDS);
|
|
|
|
assert.strictEqual(reqs, ROUNDS * ATTEMPTS_PER_ROUND);
|
2012-04-30 00:58:15 +02:00
|
|
|
assert(check_called);
|
|
|
|
});
|