Permalink
Browse files

factored out http test

  • Loading branch information...
1 parent 7931f1e commit f879dd9b44e02ac9d8ec2da3031dd9c7016c465b @substack committed Jan 14, 2012
Showing with 20 additions and 17 deletions.
  1. +20 −17 test/http.js
View
@@ -1,35 +1,38 @@
var test = require('tap').test;
-var toss = require('../');
var http = require('http');
+var toss = require('../');
-test('http request timeout failure', function (t) {
+function withServer (cb) {
var port = Math.floor(Math.random() * 5e5 + 1e4);
+ var get = function (fn) {
+ http.get({ port : port, path : '/' }, function (res) {
+ res.on('end', fn);
+ });
+ };
+
+ var server = http.createServer(function (req, res) {
+ setTimeout(function () {
+ res.end('beeeeeeeeeeeeeeeeeeeeeeeeep');
+ }, 600);
+ });
+ server.listen(port, cb.bind(null, get));
+
+ return server;
+}
+
+test('http request timeout failure', function (t) {
var tt = toss(200, function (err) {
t.ok(err);
t.end();
});
- function get (cb) {
- http.get({ port : port, path : '/' }, function (res) {
- res.on('end', cb);
- });
- }
-
- function ready () {
+ var server = withServer(function (get) {
get(tt(function () {
get(tt(function () {
- console.log('finished');
tt.end();
}));
}));
- }
-
- var server = http.createServer(function (req, res) {
- setTimeout(function () {
- res.end('beeeeeeeeeeeeeeeeeeeeeeeeep');
- }, 600);
});
- server.listen(port, ready);
t.on('end', function () {
server.close();

0 comments on commit f879dd9

Please sign in to comment.