@@ -79,6 +79,7 @@ describe('publish/subscribe', function () {
79
79
80
80
it ( 'does not fire subscribe events after reconnecting' , function ( done ) {
81
81
var i = 0 ;
82
+ var end = helper . callFuncAfter ( done , 2 ) ;
82
83
sub . on ( 'subscribe' , function ( chnl , count ) {
83
84
assert . strictEqual ( typeof count , 'number' ) ;
84
85
assert . strictEqual ( ++ i , count ) ;
@@ -91,9 +92,10 @@ describe('publish/subscribe', function () {
91
92
sub . unsubscribe ( function ( err , res ) { // Do not pass a channel here!
92
93
assert . strictEqual ( sub . pub_sub_mode , 2 ) ;
93
94
assert . deepEqual ( sub . subscription_set , { } ) ;
95
+ end ( ) ;
94
96
} ) ;
95
97
sub . set ( 'foo' , 'bar' , helper . isString ( 'OK' ) ) ;
96
- sub . subscribe ( channel2 , done ) ;
98
+ sub . subscribe ( channel2 , end ) ;
97
99
} ) ;
98
100
} ) ;
99
101
@@ -181,25 +183,19 @@ describe('publish/subscribe', function () {
181
183
sub . subscribe ( 'chan9' ) ;
182
184
sub . unsubscribe ( 'chan9' ) ;
183
185
pub . publish ( 'chan8' , 'something' ) ;
184
- sub . subscribe ( 'chan9' , function ( ) {
185
- return done ( ) ;
186
- } ) ;
186
+ sub . subscribe ( 'chan9' , done ) ;
187
187
} ) ;
188
188
189
189
it ( 'handles SUB_UNSUB_MSG_SUB 2' , function ( done ) {
190
- sub . psubscribe ( 'abc*' ) ;
190
+ sub . psubscribe ( 'abc*' , helper . isString ( 'abc*' ) ) ;
191
191
sub . subscribe ( 'xyz' ) ;
192
192
sub . unsubscribe ( 'xyz' ) ;
193
193
pub . publish ( 'abcd' , 'something' ) ;
194
- sub . subscribe ( 'xyz' , function ( ) {
195
- return done ( ) ;
196
- } ) ;
194
+ sub . subscribe ( 'xyz' , done ) ;
197
195
} ) ;
198
196
199
197
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 ) ;
203
199
sub . on ( 'subscribe' , function ( chnl , count ) {
204
200
sub . quit ( ) ;
205
201
} ) ;
@@ -236,6 +232,10 @@ describe('publish/subscribe', function () {
236
232
var end = helper . callFuncAfter ( done , 2 ) ;
237
233
sub . select ( 3 ) ;
238
234
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
+ } ) ;
239
239
sub . subscribe ( 'somechannel' , 'another channel' , function ( err , res ) {
240
240
end ( ) ;
241
241
sub . stream . destroy ( ) ;
@@ -280,7 +280,7 @@ describe('publish/subscribe', function () {
280
280
281
281
it ( 'should only resubscribe to channels not unsubscribed earlier on a reconnect' , function ( done ) {
282
282
sub . subscribe ( '/foo' , '/bar' ) ;
283
- sub . unsubscribe ( '/bar' , function ( ) {
283
+ sub . batch ( ) . unsubscribe ( [ '/bar' ] , function ( ) {
284
284
pub . pubsub ( 'channels' , function ( err , res ) {
285
285
assert . deepEqual ( res , [ '/foo' ] ) ;
286
286
sub . stream . destroy ( ) ;
@@ -291,7 +291,7 @@ describe('publish/subscribe', function () {
291
291
} ) ;
292
292
} ) ;
293
293
} ) ;
294
- } ) ;
294
+ } ) . exec ( ) ;
295
295
} ) ;
296
296
297
297
it ( 'unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Withouth callbacks' , function ( done ) {
@@ -490,7 +490,7 @@ describe('publish/subscribe', function () {
490
490
return_buffers : true
491
491
} ) ;
492
492
sub2 . on ( 'ready' , function ( ) {
493
- sub2 . psubscribe ( '*' ) ;
493
+ sub2 . batch ( ) . psubscribe ( '*' , helper . isString ( '*' ) ) . exec ( ) ;
494
494
sub2 . subscribe ( '/foo' ) ;
495
495
sub2 . on ( 'pmessage' , function ( pattern , channel , message ) {
496
496
assert . strictEqual ( pattern . inspect ( ) , new Buffer ( '*' ) . inspect ( ) ) ;
@@ -501,32 +501,58 @@ describe('publish/subscribe', function () {
501
501
pub . pubsub ( 'numsub' , '/foo' , function ( err , res ) {
502
502
assert . deepEqual ( res , [ '/foo' , 2 ] ) ;
503
503
} ) ;
504
+ // sub2 is counted twice as it subscribed with psubscribe and subscribe
504
505
pub . publish ( '/foo' , 'hello world' , helper . isNumber ( 3 ) ) ;
505
506
} ) ;
506
507
} ) ;
507
508
508
509
it ( 'allows to listen to pmessageBuffer and pmessage' , function ( done ) {
509
510
var batch = sub . batch ( ) ;
511
+ var end = helper . callFuncAfter ( done , 6 ) ;
512
+ assert . strictEqual ( sub . message_buffers , false ) ;
510
513
batch . psubscribe ( '*' ) ;
511
514
batch . subscribe ( '/foo' ) ;
512
515
batch . unsubscribe ( '/foo' ) ;
513
- batch . unsubscribe ( ) ;
514
- batch . subscribe ( [ '/foo' ] ) ;
516
+ batch . unsubscribe ( helper . isNull ( ) ) ;
517
+ batch . subscribe ( [ '/foo' ] , helper . isString ( '/foo' ) ) ;
515
518
batch . exec ( ) ;
516
519
assert . strictEqual ( sub . shouldBuffer , false ) ;
517
520
sub . on ( 'pmessageBuffer' , function ( pattern , channel , message ) {
518
521
assert . strictEqual ( pattern . inspect ( ) , new Buffer ( '*' ) . inspect ( ) ) ;
519
522
assert . strictEqual ( channel . inspect ( ) , new Buffer ( '/foo' ) . inspect ( ) ) ;
520
- sub . quit ( done ) ;
523
+ sub . quit ( end ) ;
521
524
} ) ;
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 ) ;
522
527
sub . on ( 'pmessage' , function ( pattern , channel , message ) {
523
528
assert . strictEqual ( pattern , '*' ) ;
524
529
assert . strictEqual ( channel , '/foo' ) ;
530
+ assert . strictEqual ( message , 'hello world' ) ;
531
+ end ( ) ;
525
532
} ) ;
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 ( ) ;
528
537
} ) ;
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 ) ;
530
556
} ) ;
531
557
} ) ;
532
558
@@ -536,10 +562,7 @@ describe('publish/subscribe', function () {
536
562
} ) ;
537
563
538
564
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 ) ;
543
566
} ) ;
544
567
} ) ;
545
568
0 commit comments