Skip to content

Commit ee3cb70

Browse files
committed
tests: add concurrency test
1 parent 33ad794 commit ee3cb70

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/integration_tests/test_async_substrate_interface.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,29 @@ async def test_get_payment_info():
293293
assert partial_fee_all_options > partial_fee_no_era
294294
assert partial_fee_all_options > partial_fee_era
295295
print("test_get_payment_info succeeded")
296+
297+
298+
@pytest.mark.asyncio
299+
async def test_concurrent_rpc_requests():
300+
"""
301+
Test that multiple concurrent RPC requests on a shared connection work correctly.
302+
303+
This test verifies the fix for the issue where multiple concurrent tasks
304+
re-initializing the WebSocket connection caused requests to hang.
305+
"""
306+
print("Testing test_concurrent_rpc_requests")
307+
308+
async def concurrent_task(substrate, task_id):
309+
"""Make multiple RPC calls from a single task."""
310+
for i in range(5):
311+
result = await substrate.get_block_number(None)
312+
assert isinstance(result, int)
313+
assert result > 0
314+
315+
async with AsyncSubstrateInterface(LATENT_LITE_ENTRYPOINT) as substrate:
316+
# Run 5 concurrent tasks, each making 5 RPC calls (25 total)
317+
# This tests that the connection is properly shared without re-initialization
318+
tasks = [concurrent_task(substrate, i) for i in range(5)]
319+
await asyncio.gather(*tasks)
320+
321+
print("test_concurrent_rpc_requests succeeded")

0 commit comments

Comments
 (0)