Skip to content

Commit

Permalink
entry is invalid when last response is null.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Sculli committed May 5, 2014
1 parent 0fa88a3 commit 024961e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/entry.js
Expand Up @@ -25,6 +25,9 @@ Entry.prototype = {
// @param {number} ttl
// @return {boolean}
'isValid': function (ttl) {
if (!this.last) {
return false;
}
var now = (new Date()).getTime();
return (now - this.time) < ttl ? true : false;
},
Expand Down
1 change: 1 addition & 0 deletions lib/queue.js
Expand Up @@ -27,6 +27,7 @@ Queue.prototype = {
done = this.getHandler(entry);

if(!entry.isActive()) {
entry.active = 1;
task(null, done);
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/lib/entry.spec.js
Expand Up @@ -47,9 +47,22 @@ describe('Entry', function () {
});

describe('isValid', function () {
var clock;

beforeEach(function () {
clock = sinon.useFakeTimers();
});
afterEach(function () {
clock.restore();
});
it('should return false on a newly initialized object.', function () {
expect(entry.isValid()).to.be.false;
});
it('should return false when the time to live has expired.', function () {
entry.time = ((new Date()).getTime() - 501);
entry.last = 'something';
expect(entry.isValid(500)).to.be.false;
});
});

it('should have an isActive function', function () {
Expand Down

0 comments on commit 024961e

Please sign in to comment.