@@ -445,39 +445,72 @@ public function testMultipleDurableSubscription()
445
445
public function testQueueGroupSubscribe ()
446
446
{
447
447
448
- $ this ->c ->reconnect ();
449
-
450
448
$ subject = 'test.subscribe.qgroup. ' . uniqid ();
449
+ $ group = 'testQueueGroup ' ;
450
+ $ toSend = 100 ;
451
+
452
+ $ c1 = $ this ->c ;
453
+
454
+ $ options = new ConnectionOptions ();
455
+ $ options ->setClientID ("test-2 " );
456
+ $ options ->setClusterID ("test-cluster " );
457
+ $ c2 = new Connection ($ options );
458
+
459
+ $ c1 ->reconnect ();
460
+ $ c2 ->connect ();
451
461
452
462
$ subOptions = new \NatsStreaming \SubscriptionOptions ();
453
463
454
- $ toSend = 100 ;
455
464
456
- $ got = 0 ;
457
- $ sub = $ this ->c ->queueSubscribe ($ subject , 'testQueueGroup ' , function ($ message ) use (&$ got ) {
465
+ $ got1 = 0 ;
466
+ $ allSeqs = [];
467
+ $ sub1 = $ c1 ->queueSubscribe ($ subject , $ group , function ($ message ) use (&$ got1 , &$ allSeqs ) {
458
468
/**
459
469
* @var $message MsgProto
460
470
*/
461
- $ this ->assertEquals ($ got + 1 , $ message ->getSequence ());
462
- $ got ++;
471
+ $ allSeqs ["client1 " ][] = $ message ->getSequence ();
472
+ $ got1 ++;
473
+ }, $ subOptions );
474
+
475
+ $ got2 = 0 ;
476
+ $ sub2 = $ c2 ->queueSubscribe ($ subject , $ group , function ($ message ) use (&$ got2 , &$ allSeqs ) {
477
+ /**
478
+ * @var $message MsgProto
479
+ */
480
+ $ allSeqs ["client2 " ][] = $ message ->getSequence ();
481
+ $ got2 ++;
463
482
}, $ subOptions );
464
483
465
484
$ rs = [];
466
485
for ($ i = 0 ; $ i < $ toSend ; $ i ++) {
467
- $ rs [] = $ this -> c ->publish ($ subject , 'foobar ' . $ i );
486
+ $ rs [] = $ c1 ->publish ($ subject , 'foobar ' . $ i );
468
487
}
469
488
470
489
foreach ($ rs as $ r ) {
471
490
$ gotAck = $ r ->wait ();
472
491
$ this ->assertTrue ($ gotAck );
473
492
}
474
493
475
- $ sub ->wait ($ toSend );
494
+ $ c1 ->natsCon ()->setStreamTimeout (1 );
495
+ $ c2 ->natsCon ()->setStreamTimeout (1 );
496
+ $ c1 ->wait ();
497
+ $ c2 ->wait ();
476
498
477
499
478
- $ this ->assertEquals ($ toSend , $ got );
500
+ $ client1Seqs = $ allSeqs ["client1 " ];
501
+ $ client2Seqs = $ allSeqs ["client2 " ];
479
502
480
- $ this ->c ->close ();
503
+ $ totSeqs = array_merge ($ client1Seqs , $ client2Seqs );
504
+
505
+ $ totSeqsUnique = array_unique ($ totSeqs );
506
+
507
+
508
+ $ this ->assertEquals ($ toSend , $ got1 + $ got2 );
509
+
510
+ $ this ->assertEquals ($ toSend , count ($ totSeqsUnique ));
511
+
512
+ $ c1 ->close ();
513
+ $ c2 ->close ();
481
514
}
482
515
483
516
/**
0 commit comments