node/test/parallel/test-process-getactivehandles.js
Trevor Norris 5d7265f601 test: prevent flakey test on pi2
Looping rapidly and making new connections causes problems on pi2.
Instead create a new connection when an old connection has already been
made. Running a stress test of 600 times and they all passed.

Fixes: https://github.com/nodejs/node/issues/5302
PR-URL: https://github.com/nodejs/node/pull/5537
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Alexis Campailla <orangemocha@nodejs.org>
2016-03-03 13:51:46 -07:00

48 lines
948 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const NUM = 8;
const connections = [];
const clients = [];
var clients_counter = 0;
const server = net.createServer(function listener(c) {
connections.push(c);
}).listen(common.PORT, makeConnection);
function makeConnection() {
if (clients_counter >= NUM) return;
net.connect(common.PORT, function connected() {
clientConnected(this);
makeConnection();
});
}
function clientConnected(client) {
clients.push(client);
if (++clients_counter >= NUM)
checkAll();
}
function checkAll() {
const handles = process._getActiveHandles();
clients.forEach(function(item) {
assert.ok(handles.indexOf(item) > -1);
item.destroy();
});
connections.forEach(function(item) {
assert.ok(handles.indexOf(item) > -1);
item.end();
});
assert.ok(handles.indexOf(server) > -1);
server.close();
}