Permalink
Browse files

test http success

  • Loading branch information...
1 parent f879dd9 commit 2c7aa18bbdb9bfb434401035a9ee7266c9c7250d @substack committed Jan 14, 2012
Showing with 26 additions and 3 deletions.
  1. +26 −3 test/http.js
View
@@ -2,7 +2,7 @@ var test = require('tap').test;
var http = require('http');
var toss = require('../');
-function withServer (cb) {
+function withServer (delay, cb) {
var port = Math.floor(Math.random() * 5e5 + 1e4);
var get = function (fn) {
http.get({ port : port, path : '/' }, function (res) {
@@ -13,23 +13,46 @@ function withServer (cb) {
var server = http.createServer(function (req, res) {
setTimeout(function () {
res.end('beeeeeeeeeeeeeeeeeeeeeeeeep');
- }, 600);
+ }, delay);
});
server.listen(port, cb.bind(null, get));
return server;
}
test('http request timeout failure', function (t) {
+ t.plan(1);
+
var tt = toss(200, function (err) {
t.ok(err);
t.end();
});
- var server = withServer(function (get) {
+ var server = withServer(600, function (get) {
+ get(tt(function () {
+ get(tt(function () {
+ tt.end();
+ }));
+ }));
+ });
+
+ t.on('end', function () {
+ server.close();
+ });
+});
+
+test('http request timeout success', function (t) {
+ t.plan(1);
+ var tt = toss(function (err) {
+ t.fail(err);
+ });
+
+ var server = withServer(10, function (get) {
get(tt(function () {
get(tt(function () {
+ t.ok(true);
tt.end();
+ t.end();
}));
}));
});

0 comments on commit 2c7aa18

Please sign in to comment.