@@ -3444,10 +3444,11 @@ describe("PubSub", () => {
34443444 let client : TGlideClient | null = null ;
34453445
34463446 try {
3447- const channel1 = "test_channel1" ;
3448- const channel2 = "test_channel2" ;
3449- const channel3 = "some_channel3" ;
3450- const pattern = "test_*" ;
3447+ const runId = String ( getRandomKey ( ) ) ;
3448+ const channel1 = `test_channel1:${ runId } ` ;
3449+ const channel2 = `test_channel2:${ runId } ` ;
3450+ const channel3 = `some_channel3:${ runId } ` ;
3451+ const pattern = `test_*:${ runId } ` ;
34513452
34523453 if ( clusterMode ) {
34533454 client = await GlideClusterClient . createClient (
@@ -3460,7 +3461,10 @@ describe("PubSub", () => {
34603461 }
34613462
34623463 // Assert no channels exists yet
3463- expect ( await client . pubsubChannels ( ) ) . toEqual ( [ ] ) ;
3464+ const none = await client . pubsubChannels ( {
3465+ pattern : `*:${ runId } ` ,
3466+ } ) ;
3467+ expect ( new Set ( none ) ) . toEqual ( new Set ( [ ] ) ) ;
34643468
34653469 pubSub = createPubSubSubscription (
34663470 clusterMode ,
@@ -3482,22 +3486,55 @@ describe("PubSub", () => {
34823486 ) ;
34833487
34843488 // Test pubsubChannels without pattern
3485- const channels = await client2 . pubsubChannels ( ) ;
3486- expect ( new Set ( channels ) ) . toEqual (
3487- new Set ( [ channel1 , channel2 , channel3 ] ) ,
3488- ) ;
3489+ {
3490+ let ok = false ;
3491+ for ( let i = 0 ; i < 60 ; i ++ ) {
3492+ const channels = await client2 . pubsubChannels ( { pattern : `*:${ runId } ` } ) ;
3493+ const s = new Set ( channels ) ;
3494+ if (
3495+ s . has ( channel1 ) &&
3496+ s . has ( channel2 ) &&
3497+ s . has ( channel3 )
3498+ ) {
3499+ ok = true ;
3500+ break ;
3501+ }
3502+ await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
3503+ }
3504+ const channels = await client2 . pubsubChannels ( { pattern : `*:${ runId } ` } ) ;
3505+ expect ( new Set ( channels ) ) . toEqual (
3506+ new Set ( [ channel1 , channel2 , channel3 ] ) ,
3507+ ) ;
3508+ }
34893509
34903510 // Test pubsubChannels with pattern
3491- const channelsWithPattern = await client2 . pubsubChannels ( {
3492- pattern,
3493- } ) ;
3494- expect ( new Set ( channelsWithPattern ) ) . toEqual (
3495- new Set ( [ channel1 , channel2 ] ) ,
3496- ) ;
3511+ {
3512+ let ok = false ;
3513+ for ( let i = 0 ; i < 60 ; i ++ ) {
3514+ const channelsWithPattern =
3515+ await client2 . pubsubChannels ( { pattern } ) ;
3516+ const s = new Set ( channelsWithPattern ) ;
3517+ if (
3518+ s . has ( channel1 ) &&
3519+ s . has ( channel2 ) &&
3520+ ! s . has ( channel3 )
3521+ ) {
3522+ ok = true ;
3523+ break ;
3524+ }
3525+ await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
3526+ }
3527+ const channelsWithPattern = await client2 . pubsubChannels ( {
3528+ pattern,
3529+ } ) ;
3530+ expect ( new Set ( channelsWithPattern ) ) . toEqual (
3531+ new Set ( [ channel1 , channel2 ] ) ,
3532+ ) ;
3533+ }
34973534
34983535 // Test with non-matching pattern
34993536 const nonMatchingChannels = await client2 . pubsubChannels ( {
3500- pattern : " non_matching_*" ,
3537+ pattern : ` non_matching_*: ${ runId } ` ,
35013538 } ) ;
35023539 expect ( nonMatchingChannels . length ) . toBe ( 0 ) ;
35033540 } finally {
0 commit comments