Skip to content

Commit 85f927a

Browse files
trevnorrisMyles Borins
authored andcommitted
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: #5302 PR-URL: #5537 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Alexis Campailla <[email protected]>
1 parent c86902d commit 85f927a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
const NUM = 8;
7+
const connections = [];
8+
const clients = [];
9+
var clients_counter = 0;
10+
11+
const server = net.createServer(function listener(c) {
12+
connections.push(c);
13+
}).listen(common.PORT, makeConnection);
14+
15+
16+
function makeConnection() {
17+
if (clients_counter >= NUM) return;
18+
net.connect(common.PORT, function connected() {
19+
clientConnected(this);
20+
makeConnection();
21+
});
22+
}
23+
24+
25+
function clientConnected(client) {
26+
clients.push(client);
27+
if (++clients_counter >= NUM)
28+
checkAll();
29+
}
30+
31+
32+
function checkAll() {
33+
const handles = process._getActiveHandles();
34+
35+
clients.forEach(function(item) {
36+
assert.ok(handles.indexOf(item) > -1);
37+
item.destroy();
38+
});
39+
40+
connections.forEach(function(item) {
41+
assert.ok(handles.indexOf(item) > -1);
42+
item.end();
43+
});
44+
45+
assert.ok(handles.indexOf(server) > -1);
46+
server.close();
47+
}

0 commit comments

Comments
 (0)