forked from goodboy/tractor
1
0
Fork 0

Add timeout around test and prints for guidance

context_caching
Tyler Goodlet 2021-12-15 14:22:26 -05:00
parent 52627a6326
commit f617da6ff1
1 changed files with 15 additions and 13 deletions

View File

@ -21,6 +21,8 @@ async def streamer(
await stream.send(val)
await trio.sleep(0.001)
print('producer finished')
@acm
async def open_stream() -> Awaitable[tractor.MsgStream]:
@ -32,18 +34,16 @@ async def open_stream() -> Awaitable[tractor.MsgStream]:
ctx.open_stream() as stream,
):
yield stream
breakpoint()
print('CANCELLING STREAMER')
await portal.cancel_actor()
print('CANCELLED STREAMER')
@acm
async def maybe_open_stream(taskname: str):
async with tractor.trionics.maybe_open_context(
# NOTE: all secondary tasks should cache hit on the same key
key='stream',
mngr=open_stream(),
acm_func=open_stream,
) as (cache_hit, stream):
if cache_hit:
@ -86,13 +86,13 @@ def test_open_local_sub_to_stream():
seq = []
async for msg in stream:
seq.append(msg)
print(f'{taskname} received {msg}')
assert set(seq).issubset(set(full))
print(f'{taskname} finished')
# TODO: turns out this isn't multi-task entrant XD
# We probably need an indepotent entry semantic?
with trio.fail_after(3):
async with tractor.open_root_actor():
async with (
trio.open_nursery() as nurse,
@ -101,4 +101,6 @@ def test_open_local_sub_to_stream():
nurse.start_soon(get_sub_and_pull, f'task_{i}')
await trio.sleep(0.001)
print('all consumer tasks finished')
trio.run(main)