Add close channel test with remote arbiter

dereg_on_channel_aclose
Tyler Goodlet 2020-08-08 15:17:04 -04:00
parent c821690834
commit acd5b80f4c
1 changed files with 85 additions and 47 deletions

View File

@ -199,7 +199,7 @@ def test_subactors_unregister_on_cancel(
spawn_and_check_registry,
arb_addr,
use_signal,
False,
False, # remote arbiter
with_streaming,
arbiter_addr=arb_addr
)
@ -223,32 +223,35 @@ def test_subactors_unregister_on_cancel_remote_daemon(
spawn_and_check_registry,
arb_addr,
use_signal,
True,
True, # remote arbiter
with_streaming,
# XXX: required to use remote daemon!
arbiter_addr=arb_addr
)
@pytest.mark.parametrize('use_signal', [False, True])
def test_close_channel_explicit(
daemon,
start_method,
use_signal,
arb_addr,
):
"""Verify that closing a stream explicitly and killing the actor's
"root nursery" **before** the containing nursery tears down also
results in subactor(s) deregistering from the arbiter.
"""
async def streamer(agen):
async def streamer(agen):
async for item in agen:
print(item)
async def main():
async def close_chans_before_nursery(
arb_addr: tuple,
use_signal: bool,
remote_arbiter: bool = False,
) -> None:
# logic for how many actors should still be
# in the registry at teardown.
if remote_arbiter:
entries_at_end = 2
else:
entries_at_end = 1
async with tractor.get_arbiter(*arb_addr) as aportal:
try:
get_reg = partial(aportal.run, 'self', 'get_registry')
async with tractor.open_nursery() as tn:
portal1 = await tn.run_in_actor('consumer1', stream_forever)
agen1 = await portal1.result()
@ -262,14 +265,14 @@ def test_close_channel_explicit(
try:
await streamer(agen2)
finally:
# XXX: THIS IS THE KEY THING that happens
# **before** exiting the actor nursery block
# Kill the root nursery thus resulting in
# normal arbiter channel ops to fail during
# teardown. It doesn't seem like this is
# reliably triggered by an external SIGINT.
tractor.current_actor()._root_nursery.cancel_scope.cancel()
# tractor.current_actor()._root_nursery.cancel_scope.cancel()
# XXX: THIS IS THE KEY THING that happens
# **before** exiting the actor nursery block
# also kill off channels cuz why not
await agen1.aclose()
@ -282,12 +285,47 @@ def test_close_channel_explicit(
registry = await get_reg()
assert portal1.channel.uid not in registry
assert portal2.channel.uid not in registry
assert len(registry) == 2
assert len(registry) == entries_at_end
@pytest.mark.parametrize('use_signal', [False, True])
def test_close_channel_explicit(
start_method,
use_signal,
arb_addr,
):
"""Verify that closing a stream explicitly and killing the actor's
"root nursery" **before** the containing nursery tears down also
results in subactor(s) deregistering from the arbiter.
"""
with pytest.raises(KeyboardInterrupt):
tractor.run(
main,
close_chans_before_nursery,
arb_addr,
use_signal,
False,
# XXX: required to use remote daemon!
arbiter_addr=arb_addr
)
@pytest.mark.parametrize('use_signal', [False, True])
def test_close_channel_explicit_remote_arbiter(
daemon,
start_method,
use_signal,
arb_addr,
):
"""Verify that closing a stream explicitly and killing the actor's
"root nursery" **before** the containing nursery tears down also
results in subactor(s) deregistering from the arbiter.
"""
with pytest.raises(KeyboardInterrupt):
tractor.run(
close_chans_before_nursery,
arb_addr,
use_signal,
True,
# XXX: required to use remote daemon!
arbiter_addr=arb_addr
)