tractor/tests/test_multi_program.py

67 lines
1.7 KiB
Python
Raw Normal View History

"""
2021-02-24 20:02:02 +00:00
Multiple python programs invoking the runtime.
"""
import platform
import time
import pytest
2021-02-24 20:02:02 +00:00
import trio
import tractor
2020-08-03 18:49:46 +00:00
from conftest import (
tractor_test,
sig_prog,
_INT_SIGNAL,
_INT_RETURN_CODE,
)
def test_abort_on_sigint(daemon):
assert daemon.returncode is None
time.sleep(0.1)
sig_prog(daemon, _INT_SIGNAL)
assert daemon.returncode == _INT_RETURN_CODE
2020-08-03 18:49:46 +00:00
# XXX: oddly, couldn't get capfd.readouterr() to work here?
if platform.system() != 'Windows':
# don't check stderr on windows as its empty when sending CTRL_C_EVENT
assert "KeyboardInterrupt" in str(daemon.stderr.read())
@tractor_test
async def test_cancel_remote_arbiter(daemon, arb_addr):
assert not tractor.current_actor().is_arbiter
async with tractor.get_arbiter(*arb_addr) as portal:
await portal.cancel_actor()
time.sleep(0.1)
# the arbiter channel server is cancelled but not its main task
assert daemon.returncode is None
# no arbiter socket should exist
with pytest.raises(OSError):
async with tractor.get_arbiter(*arb_addr) as portal:
pass
2019-02-16 19:25:06 +00:00
def test_register_duplicate_name(daemon, arb_addr):
2018-11-26 16:20:53 +00:00
async def main():
2021-02-24 20:02:02 +00:00
async with tractor.open_nursery(
arbiter_addr=arb_addr,
) as n:
assert not tractor.current_actor().is_arbiter
2018-11-26 16:20:53 +00:00
p1 = await n.start_actor('doggy')
p2 = await n.start_actor('doggy')
async with tractor.wait_for_actor('doggy') as portal:
assert portal.channel.uid in (p2.channel.uid, p1.channel.uid)
2018-11-26 16:20:53 +00:00
await n.cancel()
2018-11-26 16:20:53 +00:00
# run it manually since we want to start **after**
# the other "daemon" program
2021-02-24 20:02:02 +00:00
trio.run(main)