Skip to content

Commit 3441405

Browse files
authored
Fix redis tests by isolating channels to prevent noise. (#1414)
1 parent 4f8860e commit 3441405

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

tests/datastore_redis/test_asyncio.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
from uuid import uuid4
1617

1718
import pytest
1819
from testing_support.db_settings import redis_settings
@@ -131,6 +132,9 @@ def test_async_pubsub(client, loop):
131132
messages_received = []
132133
message_received = asyncio.Event()
133134

135+
channel_1 = f"channel:{uuid4()}"
136+
channel_2 = f"channel:{uuid4()}"
137+
134138
async def reader(pubsub):
135139
while True:
136140
message = await pubsub.get_message(ignore_subscribe_messages=True)
@@ -148,13 +152,13 @@ async def _publish(client, channel, message):
148152

149153
async def _test_pubsub():
150154
async with client.pubsub() as pubsub:
151-
await pubsub.psubscribe("channel:*")
155+
await pubsub.psubscribe(channel_1, channel_2)
152156

153157
future = asyncio.create_task(reader(pubsub))
154158

155-
await _publish(client, "channel:1", "Hello")
156-
await _publish(client, "channel:2", "World")
157-
await _publish(client, "channel:1", "NOPE")
159+
await _publish(client, channel_1, "Hello")
160+
await _publish(client, channel_2, "World")
161+
await _publish(client, channel_1, "NOPE")
158162

159163
await future
160164

tests/datastore_valkey/test_asyncio.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
from uuid import uuid4
1617

1718
import pytest
1819
from testing_support.db_settings import valkey_settings
@@ -123,6 +124,9 @@ def test_async_pubsub(client, loop):
123124
messages_received = []
124125
message_received = asyncio.Event()
125126

127+
channel_1 = f"channel:{uuid4()}"
128+
channel_2 = f"channel:{uuid4()}"
129+
126130
async def reader(pubsub):
127131
while True:
128132
message = await pubsub.get_message(ignore_subscribe_messages=True)
@@ -140,13 +144,13 @@ async def _publish(client, channel, message):
140144

141145
async def _test_pubsub():
142146
async with client.pubsub() as pubsub:
143-
await pubsub.psubscribe("channel:*")
147+
await pubsub.psubscribe(channel_1, channel_2)
144148

145149
future = asyncio.create_task(reader(pubsub))
146150

147-
await _publish(client, "channel:1", "Hello")
148-
await _publish(client, "channel:2", "World")
149-
await _publish(client, "channel:1", "NOPE")
151+
await _publish(client, channel_1, "Hello")
152+
await _publish(client, channel_2, "World")
153+
await _publish(client, channel_1, "NOPE")
150154

151155
await future
152156

0 commit comments

Comments
 (0)