Skip to content

Commit 7f1e3e9

Browse files
Trottrvagg
authored andcommitted
test: remove race condition in http flood test
Timer race results in some flakiness on slower devices in CI. Remove unneeded setTimeout() and replace booleans with common.mustCall(). PR-URL: #4793 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6539c64 commit 7f1e3e9

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

test/parallel/test-http-pipeline-flood.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const assert = require('assert');
1212
// Normally when the writable stream emits a 'drain' event, the server then
1313
// uncorks the readable stream, although we arent testing that part here.
1414

15+
// The issue being tested exists in Node.js 0.10.20 and is resolved in 0.10.21
16+
// and newer.
17+
1518
switch (process.argv[2]) {
1619
case undefined:
1720
return parent();
@@ -24,8 +27,6 @@ switch (process.argv[2]) {
2427
function parent() {
2528
const http = require('http');
2629
const bigResponse = new Buffer(10240).fill('x');
27-
var gotTimeout = false;
28-
var childClosed = false;
2930
var requests = 0;
3031
var connections = 0;
3132
var backloggedReqs = 0;
@@ -57,20 +58,16 @@ function parent() {
5758
const spawn = require('child_process').spawn;
5859
const args = [__filename, 'child'];
5960
const child = spawn(process.execPath, args, { stdio: 'inherit' });
60-
child.on('close', function() {
61-
childClosed = true;
61+
child.on('close', common.mustCall(function() {
6262
server.close();
63-
});
63+
}));
6464

65-
server.setTimeout(common.platformTimeout(200), function(conn) {
66-
gotTimeout = true;
65+
server.setTimeout(200, common.mustCall(function() {
6766
child.kill();
68-
});
67+
}));
6968
});
7069

7170
process.on('exit', function() {
72-
assert(gotTimeout);
73-
assert(childClosed);
7471
assert.equal(connections, 1);
7572
});
7673
}
@@ -85,13 +82,10 @@ function child() {
8582

8683
req = new Array(10241).join(req);
8784

88-
conn.on('connect', function() {
89-
// Terminate child after flooding.
90-
setTimeout(function() { conn.destroy(); }, common.platformTimeout(1000));
91-
write();
92-
});
85+
conn.on('connect', write);
9386

94-
conn.on('drain', write);
87+
// `drain` should fire once and only once
88+
conn.on('drain', common.mustCall(write));
9589

9690
function write() {
9791
while (false !== conn.write(req, 'ascii'));

0 commit comments

Comments
 (0)