Add mid stream echoserver "bail" cases

infect_asyncio
Tyler Goodlet 2021-11-27 21:55:04 -05:00
parent 2b9b29eb71
commit 9a2de90de6
1 changed files with 18 additions and 2 deletions

View File

@ -371,7 +371,15 @@ async def trio_to_aio_echo_server(
raise RuntimeError('aio channel never stopped?')
def test_echoserver_detailed_mechanics(arb_addr):
@pytest.mark.parametrize(
'raise_error_mid_stream',
[False, Exception, KeyboardInterrupt],
ids='raise_error={}'.format,
)
def test_echoserver_detailed_mechanics(
arb_addr,
raise_error_mid_stream,
):
async def main():
async with tractor.open_nursery() as n:
@ -392,6 +400,9 @@ def test_echoserver_detailed_mechanics(arb_addr):
out = await stream.receive()
assert i == out
if raise_error_mid_stream and i == 50:
raise raise_error_mid_stream
# send terminate msg
await stream.send(None)
out = await stream.receive()
@ -412,4 +423,9 @@ def test_echoserver_detailed_mechanics(arb_addr):
# is cancelled by kbi or out of task cancellation
await p.cancel_actor()
if raise_error_mid_stream:
with pytest.raises(raise_error_mid_stream):
trio.run(main)
else:
trio.run(main)