From b04e48d4c48763beb331e1f4f050a6d88a9e9124 Mon Sep 17 00:00:00 2001 From: William Barnhart Date: Mon, 20 Jul 2026 19:11:17 +0000 Subject: [PATCH] test(consumer): fix TransactionManager stop/start-transaction assertions test__stop_transactions and test_start_transactions were skipped "Needs fixing": they used `assert_called_once_with([call("0-0"), call("1-0")])`, which asserts a single producer call taking a list of Call objects -- not what the code does. _stop_transactions/_start_transactions drive the producer once per transaction id (stop_transaction / maybe_begin_transaction with a single string arg each), so for two ids there are two calls. Assert that faithfully: `assert_has_calls([call("0-0"), call("1-0")], any_order=True)` plus `call_count == 2`. Ordering isn't asserted because the ids come from a set and traced_from_parent_span interleaves shortlabel mock accesses between the real calls. Only the Kafka producer is mocked. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL --- tests/unit/transport/test_consumer.py | 29 +++++---------------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/tests/unit/transport/test_consumer.py b/tests/unit/transport/test_consumer.py index 070066984..8a5986e58 100644 --- a/tests/unit/transport/test_consumer.py +++ b/tests/unit/transport/test_consumer.py @@ -196,43 +196,24 @@ async def test_on_rebalance(self, *, manager): await manager.on_rebalance(set(), set(), set()) - @pytest.mark.skip("Needs fixing") @pytest.mark.asyncio async def test__stop_transactions(self, *, manager, producer): tids = ["0-0", "1-0"] manager._start_new_producer = AsyncMock() await manager._stop_transactions(tids) - producer.stop_transaction.assert_called() - producer.stop_transaction.assert_called_once_with( - [ - # The problem is that some reason calls with extra - # (commented out) garbage are being included - # call.shortlabel.__bool__(), - # call.shortlabel._str__(), - call("0-0"), - # call.shortlabel.__bool__(), - # call.shortlabel._str__(), - call("1-0"), - ] + assert producer.stop_transaction.call_count == 2 + producer.stop_transaction.assert_has_calls( + [call("0-0"), call("1-0")], any_order=True ) - @pytest.mark.skip("Needs fixing") @pytest.mark.asyncio async def test_start_transactions(self, *, manager, producer): tids = ["0-0", "1-0"] manager._start_new_producer = AsyncMock() await manager._start_transactions(tids) + assert producer.maybe_begin_transaction.call_count == 2 producer.maybe_begin_transaction.assert_has_calls( - [ - # The problem is that some reason calls with extra - # (commented out) garbage are being included - # call.shortlabel.__bool__(), - # call.shortlabel._str__(), - call("0-0"), - # call.shortlabel.__bool__(), - # call.shortlabel._str__(), - call("1-0"), - ] + [call("0-0"), call("1-0")], any_order=True ) @pytest.mark.asyncio