@@ -802,6 +802,68 @@ describe('Client', () => {
802
802
803
803
assert . equal ( client . isOpen , false ) ;
804
804
} , GLOBAL . SERVERS . OPEN ) ;
805
+
806
+ testUtils . testWithClient ( 'shareded PubSub' , async publisher => {
807
+ const subscriber = publisher . duplicate ( ) ;
808
+
809
+ await subscriber . connect ( ) ;
810
+
811
+ try {
812
+ const listener = spy ( ) ;
813
+ await subscriber . sSubscribe ( 'channel' , listener ) ;
814
+
815
+ await Promise . all ( [
816
+ waitTillBeenCalled ( listener ) ,
817
+ publisher . sPublish ( 'channel' , 'message' )
818
+ ] ) ;
819
+
820
+ assert . ok ( listener . calledOnceWithExactly ( 'message' , 'channel' ) ) ;
821
+
822
+ await subscriber . sUnsubscribe ( ) ;
823
+
824
+ // should be able to send commands
825
+ await assert . doesNotReject ( subscriber . ping ( ) ) ;
826
+ } finally {
827
+ await subscriber . disconnect ( ) ;
828
+ }
829
+ } , GLOBAL . SERVERS . OPEN ) ;
830
+
831
+ testUtils . testWithClient ( 'should be able to handle errors in SUBSCRIBE' , async publisher => {
832
+ const subscriber = publisher . duplicate ( ) ;
833
+
834
+ await subscriber . connect ( ) ;
835
+
836
+ try {
837
+ const listener1 = spy ( ) ;
838
+ await subscriber . subscribe ( '1' , listener1 ) ;
839
+
840
+ await publisher . aclSetUser ( 'default' , 'resetchannels' ) ;
841
+
842
+
843
+ const listener2 = spy ( ) ;
844
+ await assert . rejects ( subscriber . subscribe ( '2' , listener2 ) ) ;
845
+
846
+ await Promise . all ( [
847
+ waitTillBeenCalled ( listener1 ) ,
848
+ publisher . aclSetUser ( 'default' , 'allchannels' ) ,
849
+ publisher . publish ( '1' , 'message' ) ,
850
+ ] ) ;
851
+ assert . ok ( listener1 . calledOnceWithExactly ( 'message' , '1' ) ) ;
852
+
853
+ await subscriber . subscribe ( '2' , listener2 ) ;
854
+
855
+ await Promise . all ( [
856
+ waitTillBeenCalled ( listener2 ) ,
857
+ publisher . publish ( '2' , 'message' ) ,
858
+ ] ) ;
859
+ assert . ok ( listener2 . calledOnceWithExactly ( 'message' , '2' ) ) ;
860
+ } finally {
861
+ await subscriber . disconnect ( ) ;
862
+ }
863
+ } , {
864
+ // this test change ACL rules, running in isolated server
865
+ ...GLOBAL . SERVERS . OPEN
866
+ } ) ;
805
867
} ) ;
806
868
807
869
testUtils . testWithClient ( 'ConnectionTimeoutError' , async client => {
0 commit comments