forked from goodboy/tractor
1
0
Fork 0

Add test to verify remote task cancellation

remote_task_cancelling
Tyler Goodlet 2018-12-10 23:13:58 -05:00
parent 32c7a06e6a
commit 47b531a43a
1 changed files with 20 additions and 9 deletions

View File

@ -13,6 +13,12 @@ async def stream_seq(sequence):
yield i yield i
await trio.sleep(0.1) await trio.sleep(0.1)
# block indefinitely waiting to be cancelled by ``aclose()`` call
with trio.open_cancel_scope() as cs:
await trio.sleep(float('inf'))
assert 0
assert cs.cancelled_caught
async def stream_from_single_subactor(): async def stream_from_single_subactor():
"""Verify we can spawn a daemon actor and retrieve streamed data. """Verify we can spawn a daemon actor and retrieve streamed data.
@ -37,15 +43,20 @@ async def stream_from_single_subactor():
) )
# it'd sure be nice to have an asyncitertools here... # it'd sure be nice to have an asyncitertools here...
iseq = iter(seq) iseq = iter(seq)
ival = next(iseq)
async for val in agen: async for val in agen:
assert val == next(iseq) assert val == ival
# TODO: test breaking the loop (should it kill the try:
# far end?) ival = next(iseq)
# break except StopIteration:
# terminate far-end async-gen # should cancel far end task which will be
# await gen.asend(None) # caught and no error is raised
# break await agen.aclose()
await trio.sleep(0.3)
try:
await agen.__anext__()
except StopAsyncIteration:
# stop all spawned subactors # stop all spawned subactors
await portal.cancel_actor() await portal.cancel_actor()
# await nursery.cancel() # await nursery.cancel()