test: refactor test-http-pipeline-flood
This extends fixes for test-https-pipeline-flood to hopefully fully eliminate its flakiness on Windows in our continuous integration process. PR-URL: https://github.com/nodejs/node/pull/3636 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
974767ec0d
commit
d9734b7cc9
@ -7,7 +7,6 @@ prefix sequential
|
|||||||
[true] # This section applies to all platforms
|
[true] # This section applies to all platforms
|
||||||
|
|
||||||
[$system==win32]
|
[$system==win32]
|
||||||
test-http-pipeline-flood : PASS,FLAKY
|
|
||||||
|
|
||||||
[$system==linux]
|
[$system==linux]
|
||||||
test-vm-syntax-error-stderr : PASS,FLAKY
|
test-vm-syntax-error-stderr : PASS,FLAKY
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
// Here we are testing the HTTP server module's flood prevention mechanism.
|
// Here we are testing the HTTP server module's flood prevention mechanism.
|
||||||
// When writeable.write returns false (ie the underlying send() indicated the
|
// When writeable.write returns false (ie the underlying send() indicated the
|
||||||
@ -18,29 +18,31 @@ switch (process.argv[2]) {
|
|||||||
case 'child':
|
case 'child':
|
||||||
return child();
|
return child();
|
||||||
default:
|
default:
|
||||||
throw new Error('wtf');
|
throw new Error(`Unexpected value: ${process.argv[2]}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parent() {
|
function parent() {
|
||||||
var http = require('http');
|
const http = require('http');
|
||||||
var bigResponse = new Buffer(10240).fill('x');
|
const bigResponse = new Buffer(10240).fill('x');
|
||||||
var gotTimeout = false;
|
var gotTimeout = false;
|
||||||
var childClosed = false;
|
var childClosed = false;
|
||||||
var requests = 0;
|
var requests = 0;
|
||||||
var connections = 0;
|
var connections = 0;
|
||||||
var backloggedReqs = 0;
|
var backloggedReqs = 0;
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
const server = http.createServer(function(req, res) {
|
||||||
requests++;
|
requests++;
|
||||||
res.setHeader('content-length', bigResponse.length);
|
res.setHeader('content-length', bigResponse.length);
|
||||||
if (!res.write(bigResponse)) {
|
if (!res.write(bigResponse)) {
|
||||||
if (backloggedReqs == 0) {
|
if (backloggedReqs === 0) {
|
||||||
// Once the native buffer fills (ie write() returns false), the flood
|
// Once the native buffer fills (ie write() returns false), the flood
|
||||||
// prevention should kick in.
|
// prevention should kick in.
|
||||||
// This means the stream should emit no more 'data' events. However we
|
// This means the stream should emit no more 'data' events. However we
|
||||||
// may still be asked to process more requests if they were read before
|
// may still be asked to process more requests if they were read before
|
||||||
// mechanism activated.
|
// the flood-prevention mechanism activated.
|
||||||
req.socket.on('data', function() { assert(false); });
|
setImmediate(() => {
|
||||||
|
req.socket.on('data', () => common.fail('Unexpected data received'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
backloggedReqs++;
|
backloggedReqs++;
|
||||||
}
|
}
|
||||||
@ -51,38 +53,32 @@ function parent() {
|
|||||||
connections++;
|
connections++;
|
||||||
});
|
});
|
||||||
|
|
||||||
server.setTimeout(200, function(conn) {
|
|
||||||
gotTimeout = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function() {
|
||||||
var spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
var args = [__filename, 'child'];
|
const args = [__filename, 'child'];
|
||||||
var child = spawn(process.execPath, args, { stdio: 'inherit' });
|
const child = spawn(process.execPath, args, { stdio: 'inherit' });
|
||||||
child.on('close', function(code) {
|
child.on('close', function() {
|
||||||
assert(!code);
|
|
||||||
childClosed = true;
|
childClosed = true;
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.setTimeout(common.platformTimeout(200), function(conn) {
|
||||||
|
gotTimeout = true;
|
||||||
|
child.kill();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
assert(gotTimeout);
|
assert(gotTimeout);
|
||||||
assert(childClosed);
|
assert(childClosed);
|
||||||
assert.equal(connections, 1);
|
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.
|
|
||||||
console.log('server got %d requests', requests);
|
|
||||||
console.log('server sent %d backlogged requests', backloggedReqs);
|
|
||||||
|
|
||||||
console.log('ok');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function child() {
|
function child() {
|
||||||
var net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
var conn = net.connect({ port: common.PORT });
|
const conn = net.connect({ port: common.PORT });
|
||||||
|
|
||||||
var req = 'GET / HTTP/1.1\r\nHost: localhost:' +
|
var req = 'GET / HTTP/1.1\r\nHost: localhost:' +
|
||||||
common.PORT + '\r\nAccept: */*\r\n\r\n';
|
common.PORT + '\r\nAccept: */*\r\n\r\n';
|
||||||
@ -90,17 +86,13 @@ function child() {
|
|||||||
req = new Array(10241).join(req);
|
req = new Array(10241).join(req);
|
||||||
|
|
||||||
conn.on('connect', function() {
|
conn.on('connect', function() {
|
||||||
//kill child after 1s of flooding
|
// Terminate child after flooding.
|
||||||
setTimeout(function() { conn.destroy(); }, 1000);
|
setTimeout(function() { conn.destroy(); }, common.platformTimeout(1000));
|
||||||
write();
|
write();
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.on('drain', write);
|
conn.on('drain', write);
|
||||||
|
|
||||||
process.on('exit', function() {
|
|
||||||
console.log('ok - child');
|
|
||||||
});
|
|
||||||
|
|
||||||
function write() {
|
function write() {
|
||||||
while (false !== conn.write(req, 'ascii'));
|
while (false !== conn.write(req, 'ascii'));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user