Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove race condition in http flood test #4793

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions test/parallel/test-http-pipeline-flood.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const assert = require('assert');
// Normally when the writable stream emits a 'drain' event, the server then
// uncorks the readable stream, although we arent testing that part here.

// The issue being tested exists in Node.js 0.10.20 and is resolved in 0.10.21
// and newer.

switch (process.argv[2]) {
case undefined:
return parent();
Expand All @@ -24,8 +27,6 @@ switch (process.argv[2]) {
function parent() {
const http = require('http');
const bigResponse = new Buffer(10240).fill('x');
var gotTimeout = false;
var childClosed = false;
var requests = 0;
var connections = 0;
var backloggedReqs = 0;
Expand Down Expand Up @@ -57,20 +58,16 @@ function parent() {
const spawn = require('child_process').spawn;
const args = [__filename, 'child'];
const child = spawn(process.execPath, args, { stdio: 'inherit' });
child.on('close', function() {
childClosed = true;
child.on('close', common.mustCall(function() {
server.close();
});
}));

server.setTimeout(common.platformTimeout(200), function(conn) {
gotTimeout = true;
server.setTimeout(200, common.mustCall(function() {
child.kill();
});
}));
});

process.on('exit', function() {
assert(gotTimeout);
assert(childClosed);
assert.equal(connections, 1);
});
}
Expand All @@ -85,13 +82,10 @@ function child() {

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

conn.on('connect', function() {
// Terminate child after flooding.
setTimeout(function() { conn.destroy(); }, common.platformTimeout(1000));
write();
});
conn.on('connect', write);

conn.on('drain', write);
// `drain` should fire once and only once
conn.on('drain', common.mustCall(write));

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