Skip to content

Commit c197826

Browse files
committed
Add a test for proper ConnectionClosedOK sub manager handling
1 parent 7432f93 commit c197826

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

newsfragments/3690.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Properly handle ``PersistentConnectionClosedOK`` for ``subscription_manager.handle_subscriptions()``.

tests/core/providers/test_websocket_provider.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ async def test_async_iterator_pattern_exception_handling_for_subscriptions():
397397

398398

399399
@pytest.mark.asyncio
400-
async def test_connection_closed_ok_breaks_message_iteration():
400+
async def test_connection_closed_ok_breaks_process_subscriptions_iteration():
401401
with patch(
402402
"web3.providers.persistent.websocket.connect",
403403
new=lambda *_1, **_2: WebSocketMessageStreamMock(
@@ -409,6 +409,22 @@ async def test_connection_closed_ok_breaks_message_iteration():
409409
pytest.fail("Should not reach this point.")
410410

411411

412+
@pytest.mark.asyncio
413+
async def test_connection_closed_ok_breaks_handle_subscriptions_iteration():
414+
with patch(
415+
"web3.providers.persistent.websocket.connect",
416+
new=lambda *_1, **_2: WebSocketMessageStreamMock(
417+
raise_exception=ConnectionClosedOK(None, None)
418+
),
419+
):
420+
w3 = await AsyncWeb3(WebSocketProvider("ws://mocked"))
421+
# would fail with a ``TimeoutError`` if the iteration did not break properly
422+
# on ``ConnectionClosedOK``
423+
await asyncio.wait_for(
424+
w3.subscription_manager.handle_subscriptions(run_forever=True), timeout=1
425+
)
426+
427+
412428
@pytest.mark.asyncio
413429
async def test_listener_task_breaks_out_of_stream_when_cancelled():
414430
with patch(

0 commit comments

Comments
 (0)