summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2015-11-02 15:39:21 -0800
committerRich Trott <rtrott@gmail.com>2015-11-13 05:16:21 -0800
commitd9734b7cc958c21d3c086ef6b6f3cb6d9d646570 (patch)
treea826d650d0ac93d5bc2c5c5f2ad1d2a588715c7a /test
parent974767ec0d6ecb9f6327efb98d787221ce7e3100 (diff)
downloadandroid-node-v8-d9734b7cc958c21d3c086ef6b6f3cb6d9d646570.tar.gz
android-node-v8-d9734b7cc958c21d3c086ef6b6f3cb6d9d646570.tar.bz2
android-node-v8-d9734b7cc958c21d3c086ef6b6f3cb6d9d646570.zip
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>
Diffstat (limited to 'test')
-rw-r--r--test/sequential/sequential.status1
-rw-r--r--test/sequential/test-http-pipeline-flood.js56
2 files changed, 24 insertions, 33 deletions
diff --git a/test/sequential/sequential.status b/test/sequential/sequential.status
index 06057555d7..7d5e6f1c1e 100644
--- a/test/sequential/sequential.status
+++ b/test/sequential/sequential.status
@@ -7,7 +7,6 @@ prefix sequential
[true] # This section applies to all platforms
[$system==win32]
-test-http-pipeline-flood : PASS,FLAKY
[$system==linux]
test-vm-syntax-error-stderr : PASS,FLAKY
diff --git a/test/sequential/test-http-pipeline-flood.js b/test/sequential/test-http-pipeline-flood.js
index f8de38c7a8..571636ffed 100644
--- a/test/sequential/test-http-pipeline-flood.js
+++ b/test/sequential/test-http-pipeline-flood.js
@@ -1,6 +1,6 @@
'use strict';
-var common = require('../common');
-var assert = require('assert');
+const common = require('../common');
+const assert = require('assert');
// Here we are testing the HTTP server module's flood prevention mechanism.
// When writeable.write returns false (ie the underlying send() indicated the
@@ -18,29 +18,31 @@ switch (process.argv[2]) {
case 'child':
return child();
default:
- throw new Error('wtf');
+ throw new Error(`Unexpected value: ${process.argv[2]}`);
}
function parent() {
- var http = require('http');
- var bigResponse = new Buffer(10240).fill('x');
+ 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;
- var server = http.createServer(function(req, res) {
+ const server = http.createServer(function(req, res) {
requests++;
res.setHeader('content-length', bigResponse.length);
if (!res.write(bigResponse)) {
- if (backloggedReqs == 0) {
+ if (backloggedReqs === 0) {
// Once the native buffer fills (ie write() returns false), the flood
// prevention should kick in.
// 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
- // mechanism activated.
- req.socket.on('data', function() { assert(false); });
+ // the flood-prevention mechanism activated.
+ setImmediate(() => {
+ req.socket.on('data', () => common.fail('Unexpected data received'));
+ });
}
backloggedReqs++;
}
@@ -51,38 +53,32 @@ function parent() {
connections++;
});
- server.setTimeout(200, function(conn) {
- gotTimeout = true;
- });
-
server.listen(common.PORT, function() {
- var spawn = require('child_process').spawn;
- var args = [__filename, 'child'];
- var child = spawn(process.execPath, args, { stdio: 'inherit' });
- child.on('close', function(code) {
- assert(!code);
+ const spawn = require('child_process').spawn;
+ const args = [__filename, 'child'];
+ const child = spawn(process.execPath, args, { stdio: 'inherit' });
+ child.on('close', function() {
childClosed = true;
server.close();
});
+
+ server.setTimeout(common.platformTimeout(200), function(conn) {
+ gotTimeout = true;
+ child.kill();
+ });
});
process.on('exit', function() {
assert(gotTimeout);
assert(childClosed);
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() {
- 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:' +
common.PORT + '\r\nAccept: */*\r\n\r\n';
@@ -90,17 +86,13 @@ function child() {
req = new Array(10241).join(req);
conn.on('connect', function() {
- //kill child after 1s of flooding
- setTimeout(function() { conn.destroy(); }, 1000);
+ // Terminate child after flooding.
+ setTimeout(function() { conn.destroy(); }, common.platformTimeout(1000));
write();
});
conn.on('drain', write);
- process.on('exit', function() {
- console.log('ok - child');
- });
-
function write() {
while (false !== conn.write(req, 'ascii'));
}