Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #17 from neoziro/fix-unique-pop
Browse files Browse the repository at this point in the history
fix(queue): unique pop
  • Loading branch information
gregberge committed Jul 24, 2014
2 parents 33a9ad9 + 6246dda commit 50f9dc9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ TQueue.prototype.uniquePop = function (type, count,cb) {
function tryPop(cb) {
async.waterfall([
function getData(next) {
queue.redis.lindex(list, -1, next);
queue.redis.lindex(list, type === 'fifo' ? 0 : -1, next);
},
function pop(data, next) {
if (! data) return next(null, null);
Expand Down
56 changes: 56 additions & 0 deletions test/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,62 @@ describe('Taskman queue', function () {
], done);
});

it('should pop in the right direction (#fifo)', function (done) {
async.series([
function push(next) {
queue.push('test1', next);
},
function push(next) {
queue.push('test2', next);
},
function pop(next) {
queue.pop('fifo', 1, function (err, data) {
if (err) return next(err);
expect(data).to.eql(['test1']);
next();
});
},
function pop(next) {
queue.pop('fifo', 1, function (err, data) {
if (err) return next(err);
expect(data).to.eql(['test2']);
next();
});
}
], function (err) {
if (err) return done(err);
done();
});
});

it('should pop in the right direction (#lifo)', function (done) {
async.series([
function push(next) {
queue.push('test1', next);
},
function push(next) {
queue.push('test2', next);
},
function pop(next) {
queue.pop('lifo', 1, function (err, data) {
if (err) return next(err);
expect(data).to.eql(['test2']);
next();
});
},
function pop(next) {
queue.pop('lifo', 1, function (err, data) {
if (err) return next(err);
expect(data).to.eql(['test1']);
next();
});
}
], function (err) {
if (err) return done(err);
done();
});
});

it('should fetch multiple values', function (done) {
async.series([
function pushList(next) {
Expand Down

0 comments on commit 50f9dc9

Please sign in to comment.