From 683b5726a1fe4f5a344f06a778abaad44ae529b0 Mon Sep 17 00:00:00 2001 From: stevenpur Date: Sat, 9 Nov 2024 17:59:15 +0000 Subject: [PATCH 1/2] Fix text for checking syn subscribtion as previous test does not have time to test for pending_msgs==9 to occur --- tests/test.log | 8 ++++++++ tests/test_js.py | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/test.log diff --git a/tests/test.log b/tests/test.log new file mode 100644 index 00000000..caa4604c --- /dev/null +++ b/tests/test.log @@ -0,0 +1,8 @@ +============================= test session starts ============================== +platform darwin -- Python 3.11.6, pytest-8.3.3, pluggy-1.5.0 +rootdir: /Users/shang-kuanl/Downloads/nats_hackathon2024/nats.py +configfile: pyproject.toml +plugins: anyio-4.3.0 +collected 0 items + +============================ no tests ran in 0.00s ============================= diff --git a/tests/test_js.py b/tests/test_js.py index 85f8f556..35e15e49 100644 --- a/tests/test_js.py +++ b/tests/test_js.py @@ -12,6 +12,9 @@ import uuid from hashlib import sha256 +# test: dir +import os + import nats import nats.js.api import pytest @@ -1611,12 +1614,17 @@ 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 + + # print the warning that the coroutine was never awaited. + warn_msg = "coroutine 'JetStreamContext.PushSubscription.next_msg' was never awaited" + with pytest.warns(RuntimeWarning, match=warn_msg): + sub2.next_msg() + await nc.close() @async_test @@ -3610,6 +3618,7 @@ async def error_handler(e): @async_test async def test_object_big_files(self): + print('hello???') errors = [] async def error_handler(e): @@ -3657,6 +3666,7 @@ async def error_handler(e): assert info.digest == "SHA-256=mhT1pLyi9JlIaqwVmvt0wQp2x09kor_80Lirl4SDblA=" # Using a local file. + print('Current working directory:', os.getcwd(), flush=True) with open("pyproject.toml") as f: info = await obs.put("pyproject", f.buffer) assert info.name == "pyproject" From 89106177616788db8aa5d756c198ba451daea85c Mon Sep 17 00:00:00 2001 From: stevenpur Date: Sat, 9 Nov 2024 19:28:47 +0000 Subject: [PATCH 2/2] change purge expectation, as it adds 1 purge message to the stream --- tests/test_js.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_js.py b/tests/test_js.py index 35e15e49..b3704f59 100644 --- a/tests/test_js.py +++ b/tests/test_js.py @@ -2622,8 +2622,8 @@ async def error_handler(e): # Check remaining messages in the stream state. status = await kv.status() # NOTE: Behavior changed here from v2.10.9 => v2.10.10 - # assert status.values == 2 - assert status.values == 1 + assert status.values == 2 + # assert status.values == 1 entry = await kv.get("hello") assert "hello" == entry.key @@ -2638,13 +2638,13 @@ async def error_handler(e): assert 1 == entry.revision status = await kv.status() - assert status.values == 1 + assert status.values == 2 for i in range(100, 200): await kv.put(f"hello.{i}", b"Hello JS KV!") status = await kv.status() - assert status.values == 101 + assert status.values == 102 with pytest.raises(NotFoundError): await kv.get("hello.5")