Permalink
Browse files

inner timeout tests pass

  • Loading branch information...
1 parent a60d198 commit 2e2c79d60279eb2c30bc780702f5f5845af904f6 @substack committed Jan 14, 2012
Showing with 19 additions and 6 deletions.
  1. +2 −1 index.js
  2. +17 −5 test/discard.js
View
@@ -25,7 +25,7 @@ module.exports = function (outerTimeout, errCb) {
if (errCb) errCb(err)
};
}
- if (alive && timeout) {
+ else if (alive && timeout) {
var err = new Error('timeout');
var ito = setTimeout(function () {
alive = false;
@@ -50,6 +50,7 @@ module.exports = function (outerTimeout, errCb) {
self.end = function () {
alive = false;
+ clearTimeout(oto);
};
return self;
View
@@ -29,25 +29,37 @@ test('outer timeout', function (t) {
}));
});
-test('inner timeout', function (t) {
+test('inner timeout fail', function (t) {
t.plan(1);
var times = 0;
var tt = toss(function (err) {
if (++times === 1) {
t.equal(err.toString(), 'Error: timeout');
}
- else {
- t.end();
- }
+ else t.end();
});
- busy(5, tt(function () {
+ busy(tt(5, function () {
busy(tt(function () {
tt.end();
}))
}));
});
+test('inner timeout ok', function (t) {
+ var times = 0;
+ var tt = toss(function (err) {
+ t.fail(err);
+ });
+
+ busy(tt(12, function () {
+ busy(tt(11, function () {
+ tt.end();
+ t.end();
+ }))
+ }));
+});
+
function busy (cb) {
setTimeout(cb, 10);
}

0 comments on commit 2e2c79d

Please sign in to comment.