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
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():
"""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...
iseq = iter(seq)
ival = next(iseq)
async for val in agen:
assert val == next(iseq)
# TODO: test breaking the loop (should it kill the
# far end?)
# break
# terminate far-end async-gen
# await gen.asend(None)
# break
assert val == ival
try:
ival = next(iseq)
except StopIteration:
# should cancel far end task which will be
# caught and no error is raised
await agen.aclose()
await trio.sleep(0.3)
try:
await agen.__anext__()
except StopAsyncIteration:
# stop all spawned subactors
await portal.cancel_actor()
# await nursery.cancel()