forked from sequoiar/bouncy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
failing test for bouncing a closed connection
- Loading branch information
James Halliday
committed
Oct 11, 2011
1 parent
2aab73a
commit 0e42d96
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |