Skip to content

Commit 7b6a03c

Browse files
committed
make test_late_subscribe() more robuste
1 parent 011b76b commit 7b6a03c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/test_asyncio/test_pubsub.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -775,14 +775,13 @@ def callback(message):
775775
await p.subscribe(foo=callback)
776776
# wait tof the subscribe to finish. Cannot use _subscribe() because
777777
# p.run() is already accepting messages
778-
await asyncio.sleep(0.1)
779-
await r.publish("foo", "bar")
780-
message = None
781-
try:
782-
async with async_timeout.timeout(0.1):
783-
message = await messages.get()
784-
except asyncio.TimeoutError:
785-
pass
778+
while True:
779+
n = await r.publish("foo", "bar")
780+
if n == 1:
781+
break
782+
await asyncio.sleep(0.1)
783+
async with async_timeout.timeout(0.1):
784+
message = await messages.get()
786785
task.cancel()
787786
# we expect a cancelled error, not the Runtime error
788787
# ("did you forget to call subscribe()"")

0 commit comments

Comments
 (0)