Skip to content

Commit 09ab256

Browse files
committed
test: Expand cancellation unit test to both NATS and TCP request plane
1 parent 1e37c10 commit 09ab256

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/bindings/python/tests/cancellation/test_cancellation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ async def client(runtime, namespace):
165165

166166
@pytest.mark.forked
167167
@pytest.mark.asyncio
168+
@pytest.mark.parametrize("request_plane", ["nats", "tcp"], indirect=True)
168169
async def test_client_context_cancel(temp_file_store, server, client):
169170
_, handler = server
170171
context = Context()
@@ -198,6 +199,7 @@ async def test_client_context_cancel(temp_file_store, server, client):
198199

199200
@pytest.mark.forked
200201
@pytest.mark.asyncio
202+
@pytest.mark.parametrize("request_plane", ["nats", "tcp"], indirect=True)
201203
async def test_client_loop_break(temp_file_store, server, client):
202204
_, handler = server
203205
stream = await client.generate("_generate_until_context_cancelled")
@@ -230,6 +232,7 @@ async def test_client_loop_break(temp_file_store, server, client):
230232

231233
@pytest.mark.forked
232234
@pytest.mark.asyncio
235+
@pytest.mark.parametrize("request_plane", ["nats", "tcp"], indirect=True)
233236
async def test_server_context_cancel(temp_file_store, server, client):
234237
_, handler = server
235238
stream = await client.generate("_generate_and_cancel_context")
@@ -254,6 +257,7 @@ async def test_server_context_cancel(temp_file_store, server, client):
254257

255258
@pytest.mark.forked
256259
@pytest.mark.asyncio
260+
@pytest.mark.parametrize("request_plane", ["nats", "tcp"], indirect=True)
257261
async def test_server_raise_cancelled(temp_file_store, server, client):
258262
_, handler = server
259263
stream = await client.generate("_generate_and_raise_cancelled")
@@ -282,6 +286,7 @@ async def test_server_raise_cancelled(temp_file_store, server, client):
282286

283287
@pytest.mark.forked
284288
@pytest.mark.asyncio
289+
@pytest.mark.parametrize("request_plane", ["nats", "tcp"], indirect=True)
285290
async def test_client_context_already_cancelled(temp_file_store, server, client):
286291
_, handler = server
287292
context = Context()
@@ -304,6 +309,7 @@ async def test_client_context_already_cancelled(temp_file_store, server, client)
304309

305310
@pytest.mark.forked
306311
@pytest.mark.asyncio
312+
@pytest.mark.parametrize("request_plane", ["nats", "tcp"], indirect=True)
307313
async def test_client_context_cancel_before_await_request(
308314
temp_file_store, server, client
309315
):

lib/bindings/python/tests/conftest.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,34 @@ def temp_file_store():
402402
yield tmpdir
403403

404404

405+
@pytest.fixture
406+
def store_kv(request):
407+
"""
408+
KV store for runtime. Defaults to "file".
409+
410+
To iterate over multiple stores in a test:
411+
@pytest.mark.parametrize("store_kv", ["file", "etcd"], indirect=True)
412+
async def test_example(runtime):
413+
...
414+
"""
415+
return getattr(request, "param", "file")
416+
417+
418+
@pytest.fixture
419+
def request_plane(request):
420+
"""
421+
Request plane for runtime. Defaults to "nats".
422+
423+
To iterate over multiple transports in a test:
424+
@pytest.mark.parametrize("request_plane", ["tcp", "nats"], indirect=True)
425+
async def test_example(runtime):
426+
...
427+
"""
428+
return getattr(request, "param", "nats")
429+
430+
405431
@pytest.fixture(scope="function", autouse=False)
406-
async def runtime(request):
432+
async def runtime(request, store_kv, request_plane):
407433
"""
408434
Create a DistributedRuntime for testing.
409435
@@ -413,6 +439,14 @@ async def runtime(request):
413439
414440
Without @pytest.mark.forked in isolated mode, you will get "Worker already initialized"
415441
errors when multiple tests try to create runtimes in the same process.
442+
443+
The store_kv and request_plane can be customized by overriding their fixtures
444+
or using @pytest.mark.parametrize with indirect=True:
445+
446+
@pytest.mark.forked
447+
@pytest.mark.parametrize("store_kv", ["etcd"], indirect=True)
448+
async def test_with_etcd(runtime):
449+
...
416450
"""
417451
# Check if the test is marked with @pytest.mark.forked (only in isolated mode)
418452
if ENABLE_ISOLATED_ETCD_AND_NATS:
@@ -435,6 +469,6 @@ async def test_my_test(runtime):
435469
)
436470

437471
loop = asyncio.get_running_loop()
438-
runtime = DistributedRuntime(loop, "file", "nats")
472+
runtime = DistributedRuntime(loop, store_kv, request_plane)
439473
yield runtime
440474
runtime.shutdown()

0 commit comments

Comments
 (0)