Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Fix test-http-pipeline-flood.js #25870

Closed
wants to merge 1 commit 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
25 changes: 13 additions & 12 deletions test/simple/test-http-pipeline-flood.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,27 @@ function parent() {
var childClosed = false;
var requests = 0;
var connections = 0;
var backloggedReqs = 0;

var server = http.createServer(function(req, res) {
requests++;
res.setHeader('content-length', bigResponse.length);
res.end(bigResponse);
if(!res.write(bigResponse)){
if(backloggedReqs == 0){
//No new data should arrive after our responses start backing up
req.socket.on('data', function(){assert(false)})
}
backloggedReqs++;
}
res.end();
});

server.on('connection', function(conn) {
connections++;
});

// kill the connection after a bit, verifying that the
// flood of requests was eventually halted.
server.setTimeout(200, function(conn) {
gotTimeout = true;
conn.destroy();
});

server.listen(common.PORT, function() {
Expand All @@ -73,17 +78,16 @@ function parent() {
assert.equal(connections, 1);
// The number of requests we end up processing before the outgoing
// connection backs up and requires a drain is implementation-dependent.
// We can safely assume is more than 250.
console.log('server got %d requests', requests);
assert(requests >= 250);
console.log('server sent %d backlogged requests', backloggedReqs);

console.log('ok');
});
}

function child() {
var net = require('net');

var gotEpipe = false;
var conn = net.connect({ port: common.PORT });

var req = 'GET / HTTP/1.1\r\nHost: localhost:' +
Expand All @@ -92,17 +96,14 @@ function child() {
req = new Array(10241).join(req);

conn.on('connect', function() {
//kill child after 1s of flooding
setTimeout(function(){conn.destroy()}, 1000)
write();
});

conn.on('drain', write);

conn.on('error', function(er) {
gotEpipe = true;
});

process.on('exit', function() {
assert(gotEpipe);
console.log('ok - child');
});

Expand Down