@@ -565,6 +565,101 @@ describe('Protocol Test', () => {
565565 // if we haven't received a message by now we should be good
566566 setTimeout ( done , 500 ) ;
567567 } ) ;
568+
569+ it ( '2 Publishers on Same Topic' , function ( done ) {
570+ this . slow ( 2000 ) ;
571+ const nh = rosnodejs . nh ;
572+
573+ let msg1 ;
574+ const sub = nh . subscribe ( topic , msgType , ( msg ) => {
575+ msg1 = msg . data ;
576+ } ) ;
577+
578+ const pub1 = nh . advertise ( topic , msgType , { latching : true } ) ;
579+ const pub2 = nh . advertise ( topic , msgType , { latching : true } ) ;
580+
581+ expect ( pub1 ) . to . not . equal ( pub2 ) ;
582+
583+ pub1 . publish ( { data : 1 } ) ;
584+
585+ sub . once ( 'message' , ( { data} ) => {
586+ expect ( sub . getNumPublishers ( ) ) . to . equal ( 1 ) ;
587+ expect ( data ) . to . equal ( 1 ) ;
588+
589+ pub2 . publish ( { data : 2 } ) ;
590+ sub . once ( 'message' , ( { data} ) => {
591+ expect ( data ) . to . equal ( 2 ) ;
592+
593+ pub1 . shutdown ( )
594+ . then ( ( ) => {
595+ expect ( sub . getNumPublishers ( ) ) . to . equal ( 1 ) ;
596+
597+ pub2 . publish ( { data : 3 } ) ;
598+
599+ sub . once ( 'message' , ( { data} ) => {
600+ expect ( data ) . to . equal ( 3 ) ;
601+
602+ pub2 . shutdown ( )
603+ . then ( ( ) => {
604+ expect ( sub . getNumPublishers ( ) ) . to . equal ( 0 ) ;
605+ done ( ) ;
606+ } ) ;
607+ } ) ;
608+ } )
609+ } ) ;
610+ } )
611+ } ) ;
612+
613+ it ( '2 Subscribers on Same Topic' , function ( done ) {
614+ this . slow ( 2000 ) ;
615+ const nh = rosnodejs . nh ;
616+
617+ let msg1 ;
618+ const sub1 = nh . subscribe ( topic , msgType , ( msg ) => {
619+ msg1 = msg . data ;
620+ } ) ;
621+
622+ let msg2 ;
623+ const sub2 = nh . subscribe ( topic , msgType , ( msg ) => {
624+ msg2 = msg . data ;
625+ } ) ;
626+
627+ expect ( sub1 ) . to . not . equal ( msg2 ) ;
628+
629+ const pub = nh . advertise ( topic , msgType , { latching : true } ) ;
630+
631+ pub . publish ( { data : 1 } ) ;
632+
633+ sub2 . once ( 'message' , ( ) => {
634+ expect ( pub . getNumSubscribers ( ) ) . to . equal ( 1 ) ;
635+
636+ expect ( msg1 ) . to . equal ( msg2 ) ;
637+ pub . publish ( { data : 25 } ) ;
638+
639+ sub2 . once ( 'message' , ( ) => {
640+ expect ( msg1 ) . to . equal ( msg2 ) ;
641+ msg1 = null ;
642+ msg2 = null ;
643+
644+ sub1 . shutdown ( )
645+ . then ( ( ) => {
646+ pub . publish ( { data : 30 } ) ;
647+
648+ sub2 . once ( 'message' , ( ) => {
649+ expect ( msg1 ) . to . equal ( null ) ;
650+ expect ( msg2 ) . to . equal ( 30 ) ;
651+ expect ( pub . getNumSubscribers ( ) ) . to . equal ( 1 ) ;
652+
653+ sub2 . shutdown ( )
654+ . then ( ( ) => {
655+ expect ( pub . getNumSubscribers ( ) ) . to . equal ( 0 ) ;
656+ done ( ) ;
657+ } ) ;
658+ } ) ;
659+ } ) ;
660+ } ) ;
661+ } ) ;
662+ } ) ;
568663 } ) ;
569664
570665 describe ( 'Service' , ( ) => {
0 commit comments