From 85f927a774e33c892e9bea9aa623e23707f7cbc7 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Wed, 2 Mar 2016 15:23:55 -0700 Subject: [PATCH] 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 Reviewed-By: Rich Trott Reviewed-By: Alexis Campailla --- test/parallel/test-process-getactivehandles.js | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/parallel/test-process-getactivehandles.js diff --git a/test/parallel/test-process-getactivehandles.js b/test/parallel/test-process-getactivehandles.js new file mode 100644 index 0000000..e257439 --- /dev/null +++ b/test/parallel/test-process-getactivehandles.js @@ -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(); +} -- 2.7.4