From 47484c926eb1deff98c2a22180b03069bc5a0939 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:30:16 +0000 Subject: [PATCH 1/6] Initial plan From 7c9e2c9b715c7c34b5f9694b8cd1c91968c5b534 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:38:24 +0000 Subject: [PATCH 2/6] Add tests for _execute_operation with provided session and read_with_poll without vt Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> --- tests/test_queue.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/test_queue.py b/tests/test_queue.py index 4d69452..cded31c 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -480,3 +480,53 @@ def test_create_partitioned_queue_invalid_numeric_interval(pgmq_all_variants): queue_name, partition_interval=-100, retention_interval=100000 ) assert "Numeric partition interval must be positive" in str(e.value) + + +def test_read_with_poll_without_vt(pgmq_setup_teardown: PGMQ_WITH_QUEUE): + """Test read_with_poll when vt parameter is not provided (None).""" + pgmq, queue_name = pgmq_setup_teardown + + # Set a custom default vt for the pgmq instance + pgmq.vt = 100 + + # Send a message + msg_id = pgmq.send(queue_name, MSG) + + # Call read_with_poll without providing vt parameter + # It should use the default pgmq.vt value (100) + msgs = pgmq.read_with_poll( + queue_name, + vt=None, # Explicitly passing None to test the default behavior + qty=1, + max_poll_seconds=2, + poll_interval_ms=100, + ) + + assert msgs is not None + assert len(msgs) == 1 + assert msgs[0].msg_id == msg_id + assert msgs[0].message == MSG + + +def test_execute_operation_with_provided_sync_session(pgmq_by_session_maker, get_session_maker, db_session): + """Test _execute_operation with a provided sync session (tests line 181).""" + pgmq: PGMQueue = pgmq_by_session_maker + queue_name = f"test_queue_{uuid.uuid4().hex}" + + # Create a session to pass to the operation + with get_session_maker() as session: + # Create queue + pgmq.create_queue(queue_name, session=session) + + # Send a message with provided session + msg_id = pgmq.send(queue_name, MSG, session=session) + + # Read message with provided session + msg = pgmq.read(queue_name, vt=30, session=session) + + assert msg is not None + assert msg.msg_id == msg_id + assert msg.message == MSG + + # Clean up + pgmq.drop_queue(queue_name, session=session) From 56d4b50f291fad629d078f4ee4b99878825b7373 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:40:14 +0000 Subject: [PATCH 3/6] Add test for async _execute_operation path when session is None Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> --- tests/test_queue.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_queue.py b/tests/test_queue.py index cded31c..dc82f53 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -530,3 +530,25 @@ def test_execute_operation_with_provided_sync_session(pgmq_by_session_maker, get # Clean up pgmq.drop_queue(queue_name, session=session) + + +def test_execute_operation_async_with_session_none(pgmq_by_async_dsn, db_session): + """Test _execute_operation async path when session is None (tests lines 167-173).""" + pgmq: PGMQueue = pgmq_by_async_dsn + queue_name = f"test_queue_{uuid.uuid4().hex}" + + # Verify this is an async PGMQueue + assert pgmq.is_async is True + + # When session is None, _execute_operation creates a new async session + # and uses loop.run_until_complete with lines 169-172 + pgmq.create_queue(queue_name) + msg_id = pgmq.send(queue_name, MSG) + msg = pgmq.read(queue_name, vt=30) + + assert msg is not None + assert msg.msg_id == msg_id + assert msg.message == MSG + + # Clean up + pgmq.drop_queue(queue_name) From 4ed32b1c7e95811f5724abfee996fec906f3767b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:44:59 +0000 Subject: [PATCH 4/6] Remove fragile line number references from test comments Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> --- tests/test_queue.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_queue.py b/tests/test_queue.py index dc82f53..837f05f 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -509,7 +509,7 @@ def test_read_with_poll_without_vt(pgmq_setup_teardown: PGMQ_WITH_QUEUE): def test_execute_operation_with_provided_sync_session(pgmq_by_session_maker, get_session_maker, db_session): - """Test _execute_operation with a provided sync session (tests line 181).""" + """Test _execute_operation sync path when session is provided.""" pgmq: PGMQueue = pgmq_by_session_maker queue_name = f"test_queue_{uuid.uuid4().hex}" @@ -533,7 +533,7 @@ def test_execute_operation_with_provided_sync_session(pgmq_by_session_maker, get def test_execute_operation_async_with_session_none(pgmq_by_async_dsn, db_session): - """Test _execute_operation async path when session is None (tests lines 167-173).""" + """Test _execute_operation async path when session is None.""" pgmq: PGMQueue = pgmq_by_async_dsn queue_name = f"test_queue_{uuid.uuid4().hex}" @@ -541,7 +541,7 @@ def test_execute_operation_async_with_session_none(pgmq_by_async_dsn, db_session assert pgmq.is_async is True # When session is None, _execute_operation creates a new async session - # and uses loop.run_until_complete with lines 169-172 + # and uses loop.run_until_complete to execute the operation pgmq.create_queue(queue_name) msg_id = pgmq.send(queue_name, MSG) msg = pgmq.read(queue_name, vt=30) From 65913f972aa6eadbb23280cc6678154cfd99d033 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:46:30 +0000 Subject: [PATCH 5/6] Clarify comment in test_read_with_poll_without_vt Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> --- tests/test_queue.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_queue.py b/tests/test_queue.py index 837f05f..c78a670 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -492,11 +492,11 @@ def test_read_with_poll_without_vt(pgmq_setup_teardown: PGMQ_WITH_QUEUE): # Send a message msg_id = pgmq.send(queue_name, MSG) - # Call read_with_poll without providing vt parameter - # It should use the default pgmq.vt value (100) + # Call read_with_poll with vt=None to test the fallback logic + # When vt is None, it should fall back to using pgmq.vt value (100) msgs = pgmq.read_with_poll( queue_name, - vt=None, # Explicitly passing None to test the default behavior + vt=None, # Explicitly passing None to test the None fallback logic qty=1, max_poll_seconds=2, poll_interval_ms=100, From e35a29e99b4976efab0081bf347517daf6a5e946 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:47:57 +0000 Subject: [PATCH 6/6] Address final code review feedback: improve test structure and add cleanup verification Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> --- tests/test_queue.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/test_queue.py b/tests/test_queue.py index c78a670..9062b36 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -484,6 +484,7 @@ def test_create_partitioned_queue_invalid_numeric_interval(pgmq_all_variants): def test_read_with_poll_without_vt(pgmq_setup_teardown: PGMQ_WITH_QUEUE): """Test read_with_poll when vt parameter is not provided (None).""" + pgmq, queue_name = pgmq_setup_teardown # Set a custom default vt for the pgmq instance @@ -510,30 +511,40 @@ def test_read_with_poll_without_vt(pgmq_setup_teardown: PGMQ_WITH_QUEUE): def test_execute_operation_with_provided_sync_session(pgmq_by_session_maker, get_session_maker, db_session): """Test _execute_operation sync path when session is provided.""" + pgmq: PGMQueue = pgmq_by_session_maker queue_name = f"test_queue_{uuid.uuid4().hex}" - # Create a session to pass to the operation + # Create a session to pass to the operations + # Using the same session across multiple operations demonstrates + # that the sync path with provided session works correctly with get_session_maker() as session: - # Create queue + # Create queue with provided session pgmq.create_queue(queue_name, session=session) - # Send a message with provided session + # Verify queue was created + assert check_queue_exists(db_session, queue_name) is True + + # Send a message with the same provided session msg_id = pgmq.send(queue_name, MSG, session=session) - # Read message with provided session + # Read message with the same provided session msg = pgmq.read(queue_name, vt=30, session=session) assert msg is not None assert msg.msg_id == msg_id assert msg.message == MSG - # Clean up + # Clean up with the same provided session pgmq.drop_queue(queue_name, session=session) + + # Verify queue was dropped + assert check_queue_exists(db_session, queue_name) is False def test_execute_operation_async_with_session_none(pgmq_by_async_dsn, db_session): """Test _execute_operation async path when session is None.""" + pgmq: PGMQueue = pgmq_by_async_dsn queue_name = f"test_queue_{uuid.uuid4().hex}" @@ -552,3 +563,6 @@ def test_execute_operation_async_with_session_none(pgmq_by_async_dsn, db_session # Clean up pgmq.drop_queue(queue_name) + + # Verify queue was dropped + assert check_queue_exists(db_session, queue_name) is False