2016-07-20 01:42:49 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
require('../../helper');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
var BATCH_SOURCE = '../../../batch/';
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
var assert = require('../../support/assert');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-08-01 17:48:11 +08:00
|
|
|
var redisUtils = require('../../support/redis_utils');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-10-13 03:32:29 +08:00
|
|
|
|
|
|
|
var Channel = require(BATCH_SOURCE + 'pubsub/channel');
|
2016-10-12 00:28:46 +08:00
|
|
|
var JobPublisher = require(BATCH_SOURCE + 'pubsub/job-publisher');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
|
|
|
var HOST = 'wadus';
|
|
|
|
|
|
|
|
describe('job publisher', function() {
|
2016-10-17 21:02:34 +08:00
|
|
|
var jobPublisher = new JobPublisher(redisUtils.getPool());
|
2016-07-20 01:42:49 +08:00
|
|
|
|
|
|
|
it('.publish() should publish in job channel', function (done) {
|
2016-10-17 21:02:34 +08:00
|
|
|
redisUtils.getPool().acquire(Channel.DB, function (err, client) {
|
2016-07-20 01:42:49 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-10-13 03:32:29 +08:00
|
|
|
client.subscribe(Channel.NAME);
|
2016-07-20 01:42:49 +08:00
|
|
|
|
|
|
|
client.on('message', function (channel, host) {
|
|
|
|
assert.equal(host, HOST);
|
2016-10-13 03:32:29 +08:00
|
|
|
assert.equal(channel, Channel.NAME) ;
|
2016-07-20 01:42:49 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
jobPublisher.publish(HOST);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|