Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tests/datastore_redis/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import asyncio
from uuid import uuid4

import pytest
from testing_support.db_settings import redis_settings
Expand Down Expand Up @@ -131,6 +132,9 @@ def test_async_pubsub(client, loop):
messages_received = []
message_received = asyncio.Event()

channel_1 = f"channel:{uuid4()}"
channel_2 = f"channel:{uuid4()}"

async def reader(pubsub):
while True:
message = await pubsub.get_message(ignore_subscribe_messages=True)
Expand All @@ -148,13 +152,13 @@ async def _publish(client, channel, message):

async def _test_pubsub():
async with client.pubsub() as pubsub:
await pubsub.psubscribe("channel:*")
await pubsub.psubscribe(channel_1, channel_2)

future = asyncio.create_task(reader(pubsub))

await _publish(client, "channel:1", "Hello")
await _publish(client, "channel:2", "World")
await _publish(client, "channel:1", "NOPE")
await _publish(client, channel_1, "Hello")
await _publish(client, channel_2, "World")
await _publish(client, channel_1, "NOPE")

await future

Expand Down
12 changes: 8 additions & 4 deletions tests/datastore_valkey/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import asyncio
from uuid import uuid4

import pytest
from testing_support.db_settings import valkey_settings
Expand Down Expand Up @@ -123,6 +124,9 @@ def test_async_pubsub(client, loop):
messages_received = []
message_received = asyncio.Event()

channel_1 = f"channel:{uuid4()}"
channel_2 = f"channel:{uuid4()}"

async def reader(pubsub):
while True:
message = await pubsub.get_message(ignore_subscribe_messages=True)
Expand All @@ -140,13 +144,13 @@ async def _publish(client, channel, message):

async def _test_pubsub():
async with client.pubsub() as pubsub:
await pubsub.psubscribe("channel:*")
await pubsub.psubscribe(channel_1, channel_2)

future = asyncio.create_task(reader(pubsub))

await _publish(client, "channel:1", "Hello")
await _publish(client, "channel:2", "World")
await _publish(client, "channel:1", "NOPE")
await _publish(client, channel_1, "Hello")
await _publish(client, channel_2, "World")
await _publish(client, channel_1, "NOPE")

await future

Expand Down
Loading