Automattic / kue

Kue is a priority job queue backed by redis, built for node.js.
http://automattic.github.io/kue
MIT License
9.45k stars 863 forks source link

Testing when using Kue #627

Open moonglum opened 9 years ago

moonglum commented 9 years ago

Kue has a testing mode, but it seems to lack certain features. Given I have a component which adds jobs to the queue and waits for their completion to do something with the result. I want to test this component in isolation without accessing Redis (using the test mode). This is not possible right now as far as I can see it.

The following JavaScript snippet will log The Job is really done:

var queue = require('kue').createQueue();

queue.process('myJob', function(job, done) {
  done(null, 'The Job is really done');
});

var job = queue.createJob('myJob', {});
job.save();

job.on('complete', function(result) {
  console.log(result);
});

The same snippet, using test mode, will not log anything:

var queue = require('kue').createQueue();

queue.testMode.enter();

queue.process('myJob', function(job, done) {
  done(null, 'The Job is really done');
});

var job = queue.createJob('myJob', {});
job.save();

job.on('complete', function(result) {
  console.log(result);
});

I guess the reason for this is that event handling is done via Redis pub-sub. The question is: How do you test your apps? Are you using a Redis instance during testing?

behrad commented 9 years ago

current test mode is an initial small contribution from Kue users, that only operates in producer side as I remember... no worker test in it yet... any PR's are welcomed to handle worker mode and EventEmitter instead of reds pub/sub for non-redis testing.

Are you using a Redis instance during testing?

yes :)

moonglum commented 9 years ago

@behrad Okidoke, see my PR #629 :wink: