@@ -79,6 +79,7 @@ describe('publish/subscribe', function () {
7979
8080 it ( 'does not fire subscribe events after reconnecting' , function ( done ) {
8181 var i = 0 ;
82+ var end = helper . callFuncAfter ( done , 2 ) ;
8283 sub . on ( 'subscribe' , function ( chnl , count ) {
8384 assert . strictEqual ( typeof count , 'number' ) ;
8485 assert . strictEqual ( ++ i , count ) ;
@@ -91,9 +92,10 @@ describe('publish/subscribe', function () {
9192 sub . unsubscribe ( function ( err , res ) { // Do not pass a channel here!
9293 assert . strictEqual ( sub . pub_sub_mode , 2 ) ;
9394 assert . deepEqual ( sub . subscription_set , { } ) ;
95+ end ( ) ;
9496 } ) ;
9597 sub . set ( 'foo' , 'bar' , helper . isString ( 'OK' ) ) ;
96- sub . subscribe ( channel2 , done ) ;
98+ sub . subscribe ( channel2 , end ) ;
9799 } ) ;
98100 } ) ;
99101
@@ -181,25 +183,19 @@ describe('publish/subscribe', function () {
181183 sub . subscribe ( 'chan9' ) ;
182184 sub . unsubscribe ( 'chan9' ) ;
183185 pub . publish ( 'chan8' , 'something' ) ;
184- sub . subscribe ( 'chan9' , function ( ) {
185- return done ( ) ;
186- } ) ;
186+ sub . subscribe ( 'chan9' , done ) ;
187187 } ) ;
188188
189189 it ( 'handles SUB_UNSUB_MSG_SUB 2' , function ( done ) {
190- sub . psubscribe ( 'abc*' ) ;
190+ sub . psubscribe ( 'abc*' , helper . isString ( 'abc*' ) ) ;
191191 sub . subscribe ( 'xyz' ) ;
192192 sub . unsubscribe ( 'xyz' ) ;
193193 pub . publish ( 'abcd' , 'something' ) ;
194- sub . subscribe ( 'xyz' , function ( ) {
195- return done ( ) ;
196- } ) ;
194+ sub . subscribe ( 'xyz' , done ) ;
197195 } ) ;
198196
199197 it ( 'emits end event if quit is called from within subscribe' , function ( done ) {
200- sub . on ( 'end' , function ( ) {
201- return done ( ) ;
202- } ) ;
198+ sub . on ( 'end' , done ) ;
203199 sub . on ( 'subscribe' , function ( chnl , count ) {
204200 sub . quit ( ) ;
205201 } ) ;
@@ -236,6 +232,10 @@ describe('publish/subscribe', function () {
236232 var end = helper . callFuncAfter ( done , 2 ) ;
237233 sub . select ( 3 ) ;
238234 sub . set ( 'foo' , 'bar' ) ;
235+ sub . set ( 'failure' , helper . isError ( ) ) ; // Triggering a warning while subscribing should work
236+ sub . mget ( 'foo' , 'bar' , 'baz' , 'hello' , 'world' , function ( err , res ) {
237+ assert . deepEqual ( res , [ 'bar' , null , null , null , null ] ) ;
238+ } ) ;
239239 sub . subscribe ( 'somechannel' , 'another channel' , function ( err , res ) {
240240 end ( ) ;
241241 sub . stream . destroy ( ) ;
@@ -280,7 +280,7 @@ describe('publish/subscribe', function () {
280280
281281 it ( 'should only resubscribe to channels not unsubscribed earlier on a reconnect' , function ( done ) {
282282 sub . subscribe ( '/foo' , '/bar' ) ;
283- sub . unsubscribe ( '/bar' , function ( ) {
283+ sub . batch ( ) . unsubscribe ( [ '/bar' ] , function ( ) {
284284 pub . pubsub ( 'channels' , function ( err , res ) {
285285 assert . deepEqual ( res , [ '/foo' ] ) ;
286286 sub . stream . destroy ( ) ;
@@ -291,7 +291,7 @@ describe('publish/subscribe', function () {
291291 } ) ;
292292 } ) ;
293293 } ) ;
294- } ) ;
294+ } ) . exec ( ) ;
295295 } ) ;
296296
297297 it ( 'unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Withouth callbacks' , function ( done ) {
@@ -490,7 +490,7 @@ describe('publish/subscribe', function () {
490490 return_buffers : true
491491 } ) ;
492492 sub2 . on ( 'ready' , function ( ) {
493- sub2 . psubscribe ( '*' ) ;
493+ sub2 . batch ( ) . psubscribe ( '*' , helper . isString ( '*' ) ) . exec ( ) ;
494494 sub2 . subscribe ( '/foo' ) ;
495495 sub2 . on ( 'pmessage' , function ( pattern , channel , message ) {
496496 assert . strictEqual ( pattern . inspect ( ) , new Buffer ( '*' ) . inspect ( ) ) ;
@@ -501,32 +501,58 @@ describe('publish/subscribe', function () {
501501 pub . pubsub ( 'numsub' , '/foo' , function ( err , res ) {
502502 assert . deepEqual ( res , [ '/foo' , 2 ] ) ;
503503 } ) ;
504+ // sub2 is counted twice as it subscribed with psubscribe and subscribe
504505 pub . publish ( '/foo' , 'hello world' , helper . isNumber ( 3 ) ) ;
505506 } ) ;
506507 } ) ;
507508
508509 it ( 'allows to listen to pmessageBuffer and pmessage' , function ( done ) {
509510 var batch = sub . batch ( ) ;
511+ var end = helper . callFuncAfter ( done , 6 ) ;
512+ assert . strictEqual ( sub . message_buffers , false ) ;
510513 batch . psubscribe ( '*' ) ;
511514 batch . subscribe ( '/foo' ) ;
512515 batch . unsubscribe ( '/foo' ) ;
513- batch . unsubscribe ( ) ;
514- batch . subscribe ( [ '/foo' ] ) ;
516+ batch . unsubscribe ( helper . isNull ( ) ) ;
517+ batch . subscribe ( [ '/foo' ] , helper . isString ( '/foo' ) ) ;
515518 batch . exec ( ) ;
516519 assert . strictEqual ( sub . shouldBuffer , false ) ;
517520 sub . on ( 'pmessageBuffer' , function ( pattern , channel , message ) {
518521 assert . strictEqual ( pattern . inspect ( ) , new Buffer ( '*' ) . inspect ( ) ) ;
519522 assert . strictEqual ( channel . inspect ( ) , new Buffer ( '/foo' ) . inspect ( ) ) ;
520- sub . quit ( done ) ;
523+ sub . quit ( end ) ;
521524 } ) ;
525+ // Either message_buffers or buffers has to be true, but not both at the same time
526+ assert . notStrictEqual ( sub . message_buffers , sub . buffers ) ;
522527 sub . on ( 'pmessage' , function ( pattern , channel , message ) {
523528 assert . strictEqual ( pattern , '*' ) ;
524529 assert . strictEqual ( channel , '/foo' ) ;
530+ assert . strictEqual ( message , 'hello world' ) ;
531+ end ( ) ;
525532 } ) ;
526- pub . pubsub ( 'numsub' , '/foo' , function ( err , res ) {
527- assert . deepEqual ( res , [ '/foo' , 1 ] ) ;
533+ sub . on ( 'message' , function ( channel , message ) {
534+ assert . strictEqual ( channel , '/foo' ) ;
535+ assert . strictEqual ( message , 'hello world' ) ;
536+ end ( ) ;
528537 } ) ;
529- pub . publish ( '/foo' , 'hello world' , helper . isNumber ( 2 ) ) ;
538+ setTimeout ( function ( ) {
539+ pub . pubsub ( 'numsub' , '/foo' , function ( err , res ) {
540+ // There's one subscriber to this channel
541+ assert . deepEqual ( res , [ '/foo' , 1 ] ) ;
542+ end ( ) ;
543+ } ) ;
544+ pub . pubsub ( 'channels' , function ( err , res ) {
545+ // There's exactly one channel that is listened too
546+ assert . deepEqual ( res , [ '/foo' ] ) ;
547+ end ( ) ;
548+ } ) ;
549+ pub . pubsub ( 'numpat' , function ( err , res ) {
550+ // One pattern is active
551+ assert . strictEqual ( res , 1 ) ;
552+ end ( ) ;
553+ } ) ;
554+ pub . publish ( '/foo' , 'hello world' , helper . isNumber ( 2 ) ) ;
555+ } , 50 ) ;
530556 } ) ;
531557 } ) ;
532558
@@ -536,10 +562,7 @@ describe('publish/subscribe', function () {
536562 } ) ;
537563
538564 it ( 'executes callback when punsubscribe is called and there are no subscriptions' , function ( done ) {
539- pub . punsubscribe ( function ( err , results ) {
540- assert . strictEqual ( null , results ) ;
541- done ( err ) ;
542- } ) ;
565+ pub . batch ( ) . punsubscribe ( helper . isNull ( ) ) . exec ( done ) ;
543566 } ) ;
544567 } ) ;
545568
0 commit comments