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
|
|
|
|
2019-10-04 00:24:39 +08:00
|
|
|
var BATCH_SOURCE = '../../../lib/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
|
|
|
|
2019-10-04 00:24:39 +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);
|
2018-02-09 00:59:28 +08:00
|
|
|
assert.equal(channel, Channel.NAME);
|
|
|
|
client.unsubscribe(Channel.NAME);
|
2016-07-20 01:42:49 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
jobPublisher.publish(HOST);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|