Skip to content

Commit

Permalink
Added an other test
Browse files Browse the repository at this point in the history
  • Loading branch information
atheros committed Jun 5, 2014
1 parent a100635 commit 30305a6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/timed-queue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,51 @@ module.exports = {
queue.push(fn, 0);
}

var checkLoops = 10;
var ihandle = setInterval(function () {
checkLoops--;
if (checkLoops > 0 && pending > max) {
// not ready yet, keep checking
return;
}
clearInterval(ihandle);

assert.notEqual(checkLoops, 0, "Waiting for client timeout timed out!" + "[" + checkLoops + "]");
assert.equal(queue.size(), max);
assert.equal(pending, max);
queue.close();
}, 50);
},
'check default timeout 3': function (beforeExit) {
// 10 clients should timeout, 10 clients shouldn't
// order of clients is mixed
var queue = new advancedPool.TimedQueue({
defaultTimeout: 10,
checkInterval: 10
});
var fn;
var max = 10;
var max2 = 10;
var pending = 0;

for (var i = 0; i < max + max2; i++) {
if (i % 2 == 0) {
// even - timeout
fn = function (err, obj) {
pending--;
};
queue.push(fn);
} else {
// odd - don't timeout
fn = function (err, obj) {
pending--;
throw new Error("Timed out a non timingout client");
};
queue.push(fn, 0);
}
pending++;
}

var checkLoops = 10;
var ihandle = setInterval(function () {
checkLoops--;
Expand Down

0 comments on commit 30305a6

Please sign in to comment.