Skip to content

Commit

Permalink
test: prevent flakey test on pi2
Browse files Browse the repository at this point in the history
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: #5302
PR-URL: #5537
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Alexis Campailla <orangemocha@nodejs.org>
  • Loading branch information
trevnorris authored and Myles Borins committed Mar 17, 2016
1 parent 8899016 commit a1747c9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/parallel/test-process-getactivehandles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'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();
}

0 comments on commit a1747c9

Please sign in to comment.