Skip to content

Commit 0d264ba

Browse files
committed
Add test for ws shutdown timer.
1 parent 3b85edc commit 0d264ba

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/unit_tests/asyncio_/test_substrate_interface.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
from unittest.mock import AsyncMock, MagicMock
23

34
import pytest
@@ -91,3 +92,22 @@ async def test_runtime_call(monkeypatch):
9192
substrate.rpc_request.assert_any_call(
9293
"state_call", ["SubstrateApi_SubstrateMethod", "", None]
9394
)
95+
96+
97+
@pytest.mark.asyncio
98+
async def test_websocket_shutdown_timer():
99+
# using default ws shutdown timer of 5.0 seconds
100+
async with AsyncSubstrateInterface("wss://lite.sub.latent.to:443") as substrate:
101+
await substrate.get_chain_head()
102+
await asyncio.sleep(6)
103+
assert (
104+
substrate.ws._initialized is False
105+
) # connection should have closed automatically
106+
107+
# using custom ws shutdown timer of 10.0 seconds
108+
async with AsyncSubstrateInterface(
109+
"wss://lite.sub.latent.to:443", ws_shutdown_timer=10.0
110+
) as substrate:
111+
await substrate.get_chain_head()
112+
await asyncio.sleep(6) # same sleep time as before
113+
assert substrate.ws._initialized is True # connection should still be open

0 commit comments

Comments
 (0)