From 9eb7c7fbe082dd9d49964c675dc3d5dbfd8936e2 Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Sat, 19 Oct 2024 01:23:16 +0200 Subject: [PATCH] increase test coverage --- app/tests/test_async_stream.py | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/tests/test_async_stream.py b/app/tests/test_async_stream.py index d1d5911..3aaf35e 100644 --- a/app/tests/test_async_stream.py +++ b/app/tests/test_async_stream.py @@ -340,6 +340,7 @@ def create_remote(remote, test_type, with_close_hdr:bool = False): elif test_type == TestType.FWD_RUNTIME_ERROR_NO_STREAM: remote.stream = None raise RuntimeError("Peer closed") + return True def close(): return @@ -533,3 +534,39 @@ async def test_forward_runtime_error3(): await ifc.server_loop() assert cnt == 1 del ifc + +@pytest.mark.asyncio +async def test_forward_resp(): + assert asyncio.get_running_loop() + remote = StreamPtr(None) + cnt = 0 + + async def _close_cb(): + nonlocal cnt, remote, ifc + cnt += 1 + + cnt = 0 + ifc = AsyncStreamClient(fake_reader_fwd(), FakeWriter(), remote, _close_cb) + create_remote(remote, TestType.FWD_NO_EXCPT) + ifc.fwd_add(b'test-forward_msg') + await ifc.client_loop('') + assert cnt == 0 + del ifc + +@pytest.mark.asyncio +async def test_forward_resp2(): + assert asyncio.get_running_loop() + remote = StreamPtr(None) + cnt = 0 + + async def _close_cb(): + nonlocal cnt, remote, ifc + cnt += 1 + + cnt = 0 + ifc = AsyncStreamClient(fake_reader_fwd(), FakeWriter(), None, _close_cb) + create_remote(remote, TestType.FWD_NO_EXCPT) + ifc.fwd_add(b'test-forward_msg') + await ifc.client_loop('') + assert cnt == 0 + del ifc