@@ -3878,10 +3878,11 @@ describe("PubSub", () => {
38783878 let client : TGlideClient | null = null ;
38793879
38803880 try {
3881- const channel1 = "test_shardchannel1" ;
3882- const channel2 = "test_shardchannel2" ;
3883- const channel3 = "test_shardchannel3" ;
3884- const channel4 = "test_shardchannel4" ;
3881+ const runId = String ( getRandomKey ( ) ) ;
3882+ const channel1 = `test_shardchannel1:${ runId } ` ;
3883+ const channel2 = `test_shardchannel2:${ runId } ` ;
3884+ const channel3 = `test_shardchannel3:${ runId } ` ;
3885+ const channel4 = `test_shardchannel4:${ runId } ` ;
38853886
38863887 // Set up subscriptions
38873888 pubSub1 = createPubSubSubscription (
@@ -3914,14 +3915,39 @@ describe("PubSub", () => {
39143915 getOptions ( clusterMode ) ,
39153916 ) ;
39163917
3917- let subscribers = await (
3918- client as GlideClusterClient
3919- ) . pubsubShardNumSub ( [ channel1 , channel2 , channel3 ] ) ;
3920- expect ( convertGlideRecordToRecord ( subscribers ) ) . toEqual ( {
3921- [ channel1 ] : 0 ,
3922- [ channel2 ] : 0 ,
3923- [ channel3 ] : 0 ,
3924- } ) ;
3918+ // wait until zeros to avoid leftovers
3919+ {
3920+ let ok = false ;
3921+
3922+ for ( let i = 0 ; i < 60 ; i ++ ) {
3923+ const subs = await (
3924+ client as GlideClusterClient
3925+ ) . pubsubShardNumSub ( [ channel1 , channel2 , channel3 ] ) ;
3926+ const m = convertGlideRecordToRecord ( subs ) ;
3927+
3928+ if (
3929+ m [ channel1 ] === 0 &&
3930+ m [ channel2 ] === 0 &&
3931+ m [ channel3 ] === 0
3932+ ) {
3933+ ok = true ;
3934+ break ;
3935+ }
3936+
3937+ await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
3938+ }
3939+
3940+ if ( ! ok ) {
3941+ const subs = await (
3942+ client as GlideClusterClient
3943+ ) . pubsubShardNumSub ( [ channel1 , channel2 , channel3 ] ) ;
3944+ expect ( convertGlideRecordToRecord ( subs ) ) . toEqual ( {
3945+ [ channel1 ] : 0 ,
3946+ [ channel2 ] : 0 ,
3947+ [ channel3 ] : 0 ,
3948+ } ) ;
3949+ }
3950+ }
39253951
39263952 [ client1 , client2 ] = await createClients (
39273953 clusterMode ,
@@ -3938,15 +3964,52 @@ describe("PubSub", () => {
39383964 ) ;
39393965
39403966 // Test pubsubShardnumsub
3941- subscribers = await (
3942- client4 as GlideClusterClient
3943- ) . pubsubShardNumSub ( [ channel1 , channel2 , channel3 , channel4 ] ) ;
3944- expect ( convertGlideRecordToRecord ( subscribers ) ) . toEqual ( {
3945- [ channel1 ] : 1 ,
3946- [ channel2 ] : 2 ,
3947- [ channel3 ] : 3 ,
3948- [ channel4 ] : 0 ,
3949- } ) ;
3967+ {
3968+ let ok = false ;
3969+
3970+ for ( let i = 0 ; i < 60 ; i ++ ) {
3971+ const subs = await (
3972+ client4 as GlideClusterClient
3973+ ) . pubsubShardNumSub ( [
3974+ channel1 ,
3975+ channel2 ,
3976+ channel3 ,
3977+ channel4 ,
3978+ ] ) ;
3979+ const m = convertGlideRecordToRecord ( subs ) ;
3980+
3981+ if (
3982+ m [ channel1 ] === 1 &&
3983+ m [ channel2 ] === 2 &&
3984+ m [ channel3 ] === 3 &&
3985+ m [ channel4 ] === 0
3986+ ) {
3987+ ok = true ;
3988+ break ;
3989+ }
3990+
3991+ await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
3992+ }
3993+
3994+ if ( ! ok ) {
3995+ const subscribers = await (
3996+ client4 as GlideClusterClient
3997+ ) . pubsubShardNumSub ( [
3998+ channel1 ,
3999+ channel2 ,
4000+ channel3 ,
4001+ channel4 ,
4002+ ] ) ;
4003+ expect ( convertGlideRecordToRecord ( subscribers ) ) . toEqual (
4004+ {
4005+ [ channel1 ] : 1 ,
4006+ [ channel2 ] : 2 ,
4007+ [ channel3 ] : 3 ,
4008+ [ channel4 ] : 0 ,
4009+ } ,
4010+ ) ;
4011+ }
4012+ }
39504013
39514014 // Test pubsubShardnumsub with no channels
39524015 const emptySubscribers = await (
0 commit comments