2018-09-08 13:44:29 +00:00
|
|
|
"""
|
2021-02-24 20:02:02 +00:00
|
|
|
Multiple python programs invoking the runtime.
|
2018-09-08 13:44:29 +00:00
|
|
|
"""
|
2019-03-31 00:59:10 +00:00
|
|
|
import platform
|
2018-09-08 13:44:29 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
2021-02-24 20:02:02 +00:00
|
|
|
import trio
|
2018-09-08 13:44:29 +00:00
|
|
|
import tractor
|
2020-08-03 18:49:46 +00:00
|
|
|
from conftest import (
|
|
|
|
tractor_test,
|
|
|
|
sig_prog,
|
|
|
|
_INT_SIGNAL,
|
|
|
|
_INT_RETURN_CODE,
|
|
|
|
)
|
2018-09-08 13:44:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_abort_on_sigint(daemon):
|
|
|
|
assert daemon.returncode is None
|
|
|
|
time.sleep(0.1)
|
2019-03-10 03:48:50 +00:00
|
|
|
sig_prog(daemon, _INT_SIGNAL)
|
|
|
|
assert daemon.returncode == _INT_RETURN_CODE
|
2020-08-03 18:49:46 +00:00
|
|
|
|
2018-09-08 13:44:29 +00:00
|
|
|
# XXX: oddly, couldn't get capfd.readouterr() to work here?
|
2019-03-10 03:48:50 +00:00
|
|
|
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())
|
2018-09-08 13:44:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@tractor_test
|
|
|
|
async def test_cancel_remote_arbiter(daemon, arb_addr):
|
2018-09-17 13:11:14 +00:00
|
|
|
assert not tractor.current_actor().is_arbiter
|
2018-09-08 13:44:29 +00:00
|
|
|
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-09-08 13:44:29 +00:00
|
|
|
|
2018-11-26 16:20:53 +00:00
|
|
|
await n.cancel()
|
2018-09-08 13:44:29 +00:00
|
|
|
|
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)
|