2016-01-22 19:43:41 +08:00
|
|
|
var JobQueue = require('../../../batch/job_queue');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
describe('batch API job queue', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.metadataBackend = {
|
|
|
|
redisCmd: function () {
|
|
|
|
var callback = arguments[arguments.length -1];
|
|
|
|
process.nextTick(function () {
|
|
|
|
callback(null, 'irrelevantJob');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-06-30 00:29:53 +08:00
|
|
|
this.jobPublisher = {
|
|
|
|
publish: function () {}
|
|
|
|
};
|
|
|
|
this.jobQueue = new JobQueue(this.metadataBackend, this.jobPublisher);
|
2016-01-22 19:43:41 +08:00
|
|
|
});
|
|
|
|
|
2016-01-23 02:31:25 +08:00
|
|
|
it('.enqueue() should enqueue the provided job', function (done) {
|
2016-06-30 00:29:53 +08:00
|
|
|
this.jobQueue.enqueue('irrelevantJob', 'irrelevantHost', function (err) {
|
2016-01-22 19:43:41 +08:00
|
|
|
assert.ok(!err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 02:31:25 +08:00
|
|
|
it('.dequeue() should dequeue the next job', function (done) {
|
2016-06-30 00:29:53 +08:00
|
|
|
this.jobQueue.dequeue('irrelevantHost', function (err) {
|
2016-01-22 19:43:41 +08:00
|
|
|
assert.ok(!err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 02:31:25 +08:00
|
|
|
it('.enqueueFirst() should dequeue the next job', function (done) {
|
2016-06-30 00:29:53 +08:00
|
|
|
this.jobQueue.enqueueFirst('irrelevantJob', 'irrelevantHost', function (err) {
|
2016-01-23 02:31:25 +08:00
|
|
|
assert.ok(!err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-22 19:43:41 +08:00
|
|
|
});
|