|
|
@ -79,6 +79,7 @@ describe('publish/subscribe', function () { |
|
|
|
|
|
|
|
it('does not fire subscribe events after reconnecting', function (done) { |
|
|
|
var i = 0; |
|
|
|
var end = helper.callFuncAfter(done, 2); |
|
|
|
sub.on('subscribe', function (chnl, count) { |
|
|
|
assert.strictEqual(typeof count, 'number'); |
|
|
|
assert.strictEqual(++i, count); |
|
|
@ -91,9 +92,10 @@ describe('publish/subscribe', function () { |
|
|
|
sub.unsubscribe(function (err, res) { // Do not pass a channel here!
|
|
|
|
assert.strictEqual(sub.pub_sub_mode, 2); |
|
|
|
assert.deepEqual(sub.subscription_set, {}); |
|
|
|
end(); |
|
|
|
}); |
|
|
|
sub.set('foo', 'bar', helper.isString('OK')); |
|
|
|
sub.subscribe(channel2, done); |
|
|
|
sub.subscribe(channel2, end); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -181,25 +183,19 @@ describe('publish/subscribe', function () { |
|
|
|
sub.subscribe('chan9'); |
|
|
|
sub.unsubscribe('chan9'); |
|
|
|
pub.publish('chan8', 'something'); |
|
|
|
sub.subscribe('chan9', function () { |
|
|
|
return done(); |
|
|
|
}); |
|
|
|
sub.subscribe('chan9', done); |
|
|
|
}); |
|
|
|
|
|
|
|
it('handles SUB_UNSUB_MSG_SUB 2', function (done) { |
|
|
|
sub.psubscribe('abc*'); |
|
|
|
sub.psubscribe('abc*', helper.isString('abc*')); |
|
|
|
sub.subscribe('xyz'); |
|
|
|
sub.unsubscribe('xyz'); |
|
|
|
pub.publish('abcd', 'something'); |
|
|
|
sub.subscribe('xyz', function () { |
|
|
|
return done(); |
|
|
|
}); |
|
|
|
sub.subscribe('xyz', done); |
|
|
|
}); |
|
|
|
|
|
|
|
it('emits end event if quit is called from within subscribe', function (done) { |
|
|
|
sub.on('end', function () { |
|
|
|
return done(); |
|
|
|
}); |
|
|
|
sub.on('end', done); |
|
|
|
sub.on('subscribe', function (chnl, count) { |
|
|
|
sub.quit(); |
|
|
|
}); |
|
|
@ -236,6 +232,10 @@ describe('publish/subscribe', function () { |
|
|
|
var end = helper.callFuncAfter(done, 2); |
|
|
|
sub.select(3); |
|
|
|
sub.set('foo', 'bar'); |
|
|
|
sub.set('failure', helper.isError()); // Triggering a warning while subscribing should work
|
|
|
|
sub.mget('foo', 'bar', 'baz', 'hello', 'world', function (err, res) { |
|
|
|
assert.deepEqual(res, ['bar', null, null, null, null]); |
|
|
|
}); |
|
|
|
sub.subscribe('somechannel', 'another channel', function (err, res) { |
|
|
|
end(); |
|
|
|
sub.stream.destroy(); |
|
|
@ -280,7 +280,7 @@ describe('publish/subscribe', function () { |
|
|
|
|
|
|
|
it('should only resubscribe to channels not unsubscribed earlier on a reconnect', function (done) { |
|
|
|
sub.subscribe('/foo', '/bar'); |
|
|
|
sub.unsubscribe('/bar', function () { |
|
|
|
sub.batch().unsubscribe(['/bar'], function () { |
|
|
|
pub.pubsub('channels', function (err, res) { |
|
|
|
assert.deepEqual(res, ['/foo']); |
|
|
|
sub.stream.destroy(); |
|
|
@ -291,7 +291,7 @@ describe('publish/subscribe', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}).exec(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Withouth callbacks', function (done) { |
|
|
@ -490,7 +490,7 @@ describe('publish/subscribe', function () { |
|
|
|
return_buffers: true |
|
|
|
}); |
|
|
|
sub2.on('ready', function () { |
|
|
|
sub2.psubscribe('*'); |
|
|
|
sub2.batch().psubscribe('*', helper.isString('*')).exec(); |
|
|
|
sub2.subscribe('/foo'); |
|
|
|
sub2.on('pmessage', function (pattern, channel, message) { |
|
|
|
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect()); |
|
|
@ -501,32 +501,58 @@ describe('publish/subscribe', function () { |
|
|
|
pub.pubsub('numsub', '/foo', function (err, res) { |
|
|
|
assert.deepEqual(res, ['/foo', 2]); |
|
|
|
}); |
|
|
|
// sub2 is counted twice as it subscribed with psubscribe and subscribe
|
|
|
|
pub.publish('/foo', 'hello world', helper.isNumber(3)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('allows to listen to pmessageBuffer and pmessage', function (done) { |
|
|
|
var batch = sub.batch(); |
|
|
|
var end = helper.callFuncAfter(done, 6); |
|
|
|
assert.strictEqual(sub.message_buffers, false); |
|
|
|
batch.psubscribe('*'); |
|
|
|
batch.subscribe('/foo'); |
|
|
|
batch.unsubscribe('/foo'); |
|
|
|
batch.unsubscribe(); |
|
|
|
batch.subscribe(['/foo']); |
|
|
|
batch.unsubscribe(helper.isNull()); |
|
|
|
batch.subscribe(['/foo'], helper.isString('/foo')); |
|
|
|
batch.exec(); |
|
|
|
assert.strictEqual(sub.shouldBuffer, false); |
|
|
|
sub.on('pmessageBuffer', function (pattern, channel, message) { |
|
|
|
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect()); |
|
|
|
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect()); |
|
|
|
sub.quit(done); |
|
|
|
sub.quit(end); |
|
|
|
}); |
|
|
|
// Either message_buffers or buffers has to be true, but not both at the same time
|
|
|
|
assert.notStrictEqual(sub.message_buffers, sub.buffers); |
|
|
|
sub.on('pmessage', function (pattern, channel, message) { |
|
|
|
assert.strictEqual(pattern, '*'); |
|
|
|
assert.strictEqual(channel, '/foo'); |
|
|
|
assert.strictEqual(message, 'hello world'); |
|
|
|
end(); |
|
|
|
}); |
|
|
|
pub.pubsub('numsub', '/foo', function (err, res) { |
|
|
|
assert.deepEqual(res, ['/foo', 1]); |
|
|
|
sub.on('message', function (channel, message) { |
|
|
|
assert.strictEqual(channel, '/foo'); |
|
|
|
assert.strictEqual(message, 'hello world'); |
|
|
|
end(); |
|
|
|
}); |
|
|
|
pub.publish('/foo', 'hello world', helper.isNumber(2)); |
|
|
|
setTimeout(function () { |
|
|
|
pub.pubsub('numsub', '/foo', function (err, res) { |
|
|
|
// There's one subscriber to this channel
|
|
|
|
assert.deepEqual(res, ['/foo', 1]); |
|
|
|
end(); |
|
|
|
}); |
|
|
|
pub.pubsub('channels', function (err, res) { |
|
|
|
// There's exactly one channel that is listened too
|
|
|
|
assert.deepEqual(res, ['/foo']); |
|
|
|
end(); |
|
|
|
}); |
|
|
|
pub.pubsub('numpat', function (err, res) { |
|
|
|
// One pattern is active
|
|
|
|
assert.strictEqual(res, 1); |
|
|
|
end(); |
|
|
|
}); |
|
|
|
pub.publish('/foo', 'hello world', helper.isNumber(2)); |
|
|
|
}, 50); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -536,10 +562,7 @@ describe('publish/subscribe', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('executes callback when punsubscribe is called and there are no subscriptions', function (done) { |
|
|
|
pub.punsubscribe(function (err, results) { |
|
|
|
assert.strictEqual(null, results); |
|
|
|
done(err); |
|
|
|
}); |
|
|
|
pub.batch().punsubscribe(helper.isNull()).exec(done); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|