Skip to content

Commit

Permalink
failing test for bouncing a closed connection
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Oct 11, 2011
1 parent 2aab73a commit 0e42d96
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/raw_drop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var test = require('tap').test;
var bouncy = require('bouncy');
var net = require('net');

test('drop a socket', function (t) {
t.plan(2);

var p0 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
var p1 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);

var s0 = bouncy(function (req, bounce) {
t.equal(req.headers.host, 'lulzy');

var c = net.createConnection(p1, function () {
c.destroy();
t.doesNotThrow(
function () { bounce(c) },
'bounce should not throw when the connection is closed'
);

process.nextTick(function () {
req.socket.end();
s0.close();
s1.close();
t.end();
});
});
});

var s1 = net.createServer(function (c) {
// ...
});
s1.listen(p1);

s0.listen(p0, function () {
var c = net.createConnection(p0, function () {
c.write('GET /lul HT');
setTimeout(function () {
c.write('TP/1.1\r\nHo');
}, 20);
setTimeout(function () {
c.write('st: lulz');
}, 40);
setTimeout(function () {
c.write('y\r\nFoo: bar');
}, 60);
setTimeout(function () {
c.write('\r\n\r\n');
}, 80);
setTimeout(function () {
c.end();
}, 100);
});
});
});

0 comments on commit 0e42d96

Please sign in to comment.