From 273c0a31c607089844e4635703684ad93673a903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Aksel=20R=C3=B8ysland?= Date: Mon, 5 May 2025 14:29:26 +0200 Subject: [PATCH] Consume the pending messages rather than asserting pending message count. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes flakiness in test_subscribe_push_bound() where the client-side pending message queue occasionally did not contain all the pending messages from the server by the time the test function inspected the queue, due to a race condition between the task fetching messages from the server and the task running the test function. Resolves #689. Signed-off-by: Knut Aksel Røysland --- tests/test_js.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_js.py b/tests/test_js.py index 08a6377b..a014178d 100644 --- a/tests/test_js.py +++ b/tests/test_js.py @@ -1615,11 +1615,11 @@ async def cb2(msg): # Create a sync subscriber now. sub2 = await js.subscribe("pbound", durable="two") - msg = await sub2.next_msg() - assert msg.data == b"Hello World 0" - assert msg.metadata.sequence.stream == 1 - assert msg.metadata.sequence.consumer == 1 - assert sub2.pending_msgs == 9 + for i in range(10): + msg = await sub2.next_msg() + assert msg.data == f"Hello World {i}".encode() + assert msg.metadata.sequence.stream == i + 1 + assert msg.metadata.sequence.consumer == i + 1 await nc.close()