Skip to content

Commit 0c50874

Browse files
committed
test(node): stabilize pubsub channels (unique runId + bounded wait)
Signed-off-by: hank95179 <[email protected]>
1 parent 92ec81b commit 0c50874

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

node/tests/PubSub.test.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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,12 +3486,44 @@ describe("PubSub", () => {
34823486
);
34833487

34843488
// Test pubsubChannels without pattern
3485-
const channels = await client2.pubsubChannels();
3489+
for (let i = 0; i < 60; i++) {
3490+
const channels = await client2.pubsubChannels({
3491+
pattern: `*:${runId}`,
3492+
});
3493+
const s = new Set(channels);
3494+
3495+
if (s.has(channel1) && s.has(channel2) && s.has(channel3)) {
3496+
break;
3497+
}
3498+
3499+
await new Promise((r) => setTimeout(r, 50));
3500+
}
3501+
3502+
const channels = await client2.pubsubChannels({
3503+
pattern: `*:${runId}`,
3504+
});
34863505
expect(new Set(channels)).toEqual(
34873506
new Set([channel1, channel2, channel3]),
34883507
);
34893508

34903509
// Test pubsubChannels with pattern
3510+
for (let i = 0; i < 60; i++) {
3511+
const channelsWithPattern = await client2.pubsubChannels({
3512+
pattern,
3513+
});
3514+
const s = new Set(channelsWithPattern);
3515+
3516+
if (
3517+
s.has(channel1) &&
3518+
s.has(channel2) &&
3519+
!s.has(channel3)
3520+
) {
3521+
break;
3522+
}
3523+
3524+
await new Promise((r) => setTimeout(r, 50));
3525+
}
3526+
34913527
const channelsWithPattern = await client2.pubsubChannels({
34923528
pattern,
34933529
});
@@ -3497,7 +3533,7 @@ describe("PubSub", () => {
34973533

34983534
// Test with non-matching pattern
34993535
const nonMatchingChannels = await client2.pubsubChannels({
3500-
pattern: "non_matching_*",
3536+
pattern: `non_matching_*:${runId}`,
35013537
});
35023538
expect(nonMatchingChannels.length).toBe(0);
35033539
} finally {

0 commit comments

Comments
 (0)