forked from goodboy/tractor
1
0
Fork 0

Add process tree depth control to nested multierror test

Another step toward having a complete test for #89.
Subactor breadth still seems to cause the most havoc and is why I've
kept that value to just 2 for now.
drop_event_clear
Tyler Goodlet 2019-11-24 19:22:01 -05:00
parent d2a01e8b81
commit 915bf17a9a
1 changed files with 47 additions and 25 deletions

View File

@ -261,13 +261,26 @@ async def test_some_cancels_all(num_actors_and_errs, start_method):
pytest.fail("Should have gotten a remote assertion error?") pytest.fail("Should have gotten a remote assertion error?")
async def spawn_and_error(num) -> None: async def spawn_and_error(breadth, depth) -> None:
name = tractor.current_actor().name name = tractor.current_actor().name
async with tractor.open_nursery() as nursery: async with tractor.open_nursery() as nursery:
for i in range(num): for i in range(breadth):
await nursery.run_in_actor( if depth > 0:
f'{name}_errorer_{i}', assert_err args = (
) f'spawner_{i}_depth_{depth}',
spawn_and_error,
)
kwargs = {
'breadth': breadth,
'depth': depth - 1,
}
else:
args = (
f'{name}_errorer_{i}',
assert_err,
)
kwargs = {}
await nursery.run_in_actor(*args, **kwargs)
@tractor_test @tractor_test
@ -276,25 +289,34 @@ async def test_nested_multierrors(loglevel, start_method):
This test goes only 2 nurseries deep but we should eventually have tests This test goes only 2 nurseries deep but we should eventually have tests
for arbitrary n-depth actor trees. for arbitrary n-depth actor trees.
""" """
if platform.system() == 'Windows': # XXX: forkserver can't seem to handle any more then 2 depth
# Windows CI seems to be partifcularly fragile on Python 3.8.. # process trees for whatever reason.
num_subactors = 2 # Any more process levels then this and we start getting pretty slow anyway
else: depth = 3
# XXX: any more then this and the forkserver will subactor_breadth = 2
# start bailing hard...gotta look into it
num_subactors = 4
try: with trio.fail_after(120):
async with tractor.open_nursery() as nursery: try:
async with tractor.open_nursery() as nursery:
for i in range(subactor_breadth):
await nursery.run_in_actor(
f'spawner_{i}',
spawn_and_error,
breadth=subactor_breadth,
depth=depth,
)
except trio.MultiError as err:
assert len(err.exceptions) == subactor_breadth
for subexc in err.exceptions:
assert isinstance(subexc, tractor.RemoteActorError)
if depth > 1 and subactor_breadth > 1:
for i in range(num_subactors): # XXX not sure what's up with this..
await nursery.run_in_actor( if platform.system() == 'Windows':
f'spawner_{i}', assert (subexc.type is trio.MultiError) or (
spawn_and_error, subexc.type is tractor.RemoteActorError)
num=num_subactors, else:
) assert subexc.type is trio.MultiError
except trio.MultiError as err: else:
assert len(err.exceptions) == num_subactors assert (subexc.type is tractor.RemoteActorError) or (
for subexc in err.exceptions: subexc.type is trio.Cancelled)
assert isinstance(subexc, tractor.RemoteActorError)
assert subexc.type is trio.MultiError