From 75c4a588412390311597c961930771a89686d6e7 Mon Sep 17 00:00:00 2001 From: Matthew Wolter Date: Sun, 12 Apr 2026 06:57:53 -0700 Subject: [PATCH] Fix test fixture to resolve events immediately instead of blocking The mock_dispatcher fixture's fake_subscribe recorded event handlers but never called them, causing asyncio.wait() to block for the full DEFAULT_TIMEOUT (15s) on every test that passes expected_events to send(). With 28 affected tests, the suite wasted ~8 minutes on dead waits and required an undocumented pytest-timeout plugin to complete. Add call_soon to the default fake_subscribe so futures resolve on the next event loop iteration, matching the pattern already used by setup_event_response(). Override with a non-resolving mock in test_send_timeout to preserve timeout path coverage. Suite now completes in <1 second with no --timeout flag. --- tests/unit/test_commands.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py index 44dff6f..02516e1 100644 --- a/tests/unit/test_commands.py +++ b/tests/unit/test_commands.py @@ -28,6 +28,10 @@ def mock_dispatcher(): sub.unsubscribe = MagicMock() dispatcher._last_subscribe_handler = handler dispatcher._last_subscribe_event_type = event_type + # Immediately resolve the future so send() doesn't block + asyncio.get_event_loop().call_soon( + handler, Event(event_type, {}) + ) return sub dispatcher.subscribe = MagicMock(side_effect=fake_subscribe) @@ -80,6 +84,13 @@ async def test_send_with_event(command_handler, mock_connection, mock_dispatcher async def test_send_timeout(command_handler, mock_connection, mock_dispatcher): + # Override to NOT resolve events, so we can test the timeout path + def non_resolving_subscribe(event_type, handler, attribute_filters=None): + sub = MagicMock(spec=Subscription) + sub.unsubscribe = MagicMock() + return sub + mock_dispatcher.subscribe = MagicMock(side_effect=non_resolving_subscribe) + result = await command_handler.send(b"test_command", [EventType.OK], timeout=0.1) assert result.type == EventType.ERROR assert result.payload == {"reason": "no_event_received"}