Permalink
Browse files

finally fixed the stupid keep alive leak test

  • Loading branch information...
1 parent 5f4e1ac commit 82c17bb3f81e674a10d9afb97fcb665f3bccffbc @substack committed Oct 24, 2011
Showing with 20 additions and 10 deletions.
  1. +1 −1 index.js
  2. +9 −4 test/keep_alive_leak.js
  3. +10 −5 test/post.js
View
@@ -34,7 +34,7 @@ var handler = bouncy.handler = function (cb, c) {
req.on('rawHead', onX);
req.on('rawBody', onX);
- req.on('end', function () {
+ req.on('rawEnd', function () {
req.removeListener('rawHead', onX);
req.removeListener('rawBody', onX);
});
View
@@ -32,12 +32,16 @@ test("make sure keep-alives don't leak", function (t) {
ss[0].close();
ss[1].close();
t.end();
+ sockets.forEach(function (s) { s.end() });
}
});
});
+ var sockets = [];
var ss = [ p1, p2 ].map(function (port, ix) {
var s = http.createServer(function (req, res) {
+ sockets.push(req.socket);
+
t.equal(req.method, 'POST');
t.equal(req.headers.host, [ 'beep', 'boop' ][ix]);
t.equal(req.headers.connection, 'keep-alive');
@@ -51,6 +55,10 @@ test("make sure keep-alives don't leak", function (t) {
req.on('end', function () {
t.equal(data, 'abcdefghij');
+ req.socket.on('data', function (buf) {
+ t.fail('data bleeding over');
+ });
+
res.setHeader('content-type', 'text/plain');
res.setHeader('connection', 'keep-alive');
@@ -83,7 +91,7 @@ function request (port, t, cb) {
'Connection: keep-alive',
'Transfer-Encoding: chunked',
'',
- '',
+ ''
].join('\r\n'));
var chunks = [
@@ -119,9 +127,6 @@ function request (port, t, cb) {
}
else if (mode === 'body' && lines[lines.length-2] === '0\r') {
c.removeListener('data', onData);
- c.on('data', function (buf) {
- t.fail('data from other requests bleeding over');
- });
function upcase (s) { return s.toUpperCase() }
View
@@ -1,36 +1,41 @@
var test = require('tap').test;
var bouncy = require('bouncy');
var http = require('http');
-var Stream = require('./lib/stream');
+var Stream = require('net').Stream;
test('POST with http', function (t) {
var port = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
t.plan(4);
var s = bouncy(function (req, bounce) {
t.equal(req.headers.host, 'localhost:' + port);
- var stream = Stream();
var data = '';
var alive = true;
- stream.on('data', function (buf) {
+ var stream = new Stream;
+ stream.writable = true;
+ stream.readable = true;
+
+ stream.write = function (buf) {
data += buf.toString();
if (alive && data.match(/pow!/)) {
t.ok(true, 'got post data');
stream.end();
alive = false;
}
- });
+ };
bounce(stream);
- stream.write([
+ stream.emit('data', [
'HTTP/1.1 200 200 OK',
'Content-Type: text/plain',
'Connection: close',
'',
'oh hello'
].join('\r\n'));
+
+ stream.emit('end');
});
s.listen(port, function () {

0 comments on commit 82c17bb

Please sign in to comment.