Rename fixture `arb_addr` -> `reg_addr` and set the session value globally as `._root._default_lo_addrs`
parent
190845ce1d
commit
1e689ee701
|
@ -29,7 +29,7 @@ def tractor_test(fn):
|
||||||
|
|
||||||
If fixtures:
|
If fixtures:
|
||||||
|
|
||||||
- ``arb_addr`` (a socket addr tuple where arbiter is listening)
|
- ``reg_addr`` (a socket addr tuple where arbiter is listening)
|
||||||
- ``loglevel`` (logging level passed to tractor internals)
|
- ``loglevel`` (logging level passed to tractor internals)
|
||||||
- ``start_method`` (subprocess spawning backend)
|
- ``start_method`` (subprocess spawning backend)
|
||||||
|
|
||||||
|
@ -40,16 +40,16 @@ def tractor_test(fn):
|
||||||
def wrapper(
|
def wrapper(
|
||||||
*args,
|
*args,
|
||||||
loglevel=None,
|
loglevel=None,
|
||||||
arb_addr=None,
|
reg_addr=None,
|
||||||
start_method=None,
|
start_method=None,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
# __tracebackhide__ = True
|
# __tracebackhide__ = True
|
||||||
|
|
||||||
if 'arb_addr' in inspect.signature(fn).parameters:
|
if 'reg_addr' in inspect.signature(fn).parameters:
|
||||||
# injects test suite fixture value to test as well
|
# injects test suite fixture value to test as well
|
||||||
# as `run()`
|
# as `run()`
|
||||||
kwargs['arb_addr'] = arb_addr
|
kwargs['reg_addr'] = reg_addr
|
||||||
|
|
||||||
if 'loglevel' in inspect.signature(fn).parameters:
|
if 'loglevel' in inspect.signature(fn).parameters:
|
||||||
# allows test suites to define a 'loglevel' fixture
|
# allows test suites to define a 'loglevel' fixture
|
||||||
|
@ -71,7 +71,7 @@ def tractor_test(fn):
|
||||||
async def _main():
|
async def _main():
|
||||||
async with tractor.open_root_actor(
|
async with tractor.open_root_actor(
|
||||||
# **kwargs,
|
# **kwargs,
|
||||||
arbiter_addr=arb_addr,
|
registry_addrs=[reg_addr] if reg_addr else None,
|
||||||
loglevel=loglevel,
|
loglevel=loglevel,
|
||||||
start_method=start_method,
|
start_method=start_method,
|
||||||
|
|
||||||
|
@ -92,9 +92,6 @@ def tractor_test(fn):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
_arb_addr = '127.0.0.1', random.randint(1000, 9999)
|
|
||||||
|
|
||||||
|
|
||||||
# Sending signal.SIGINT on subprocess fails on windows. Use CTRL_* alternatives
|
# Sending signal.SIGINT on subprocess fails on windows. Use CTRL_* alternatives
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
_KILL_SIGNAL = signal.CTRL_BREAK_EVENT
|
_KILL_SIGNAL = signal.CTRL_BREAK_EVENT
|
||||||
|
@ -173,9 +170,23 @@ def ci_env() -> bool:
|
||||||
return _ci_env
|
return _ci_env
|
||||||
|
|
||||||
|
|
||||||
|
# choose randomly at import time
|
||||||
|
_reg_addr: tuple[str, int] = (
|
||||||
|
'127.0.0.1',
|
||||||
|
random.randint(1000, 9999),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def arb_addr():
|
def reg_addr() -> tuple[str, int]:
|
||||||
return _arb_addr
|
|
||||||
|
# globally override the runtime to the per-test-session-dynamic
|
||||||
|
# addr so that all tests never conflict with any other actor
|
||||||
|
# tree using the default.
|
||||||
|
from tractor import _root
|
||||||
|
_root._default_lo_addrs = [_reg_addr]
|
||||||
|
|
||||||
|
return _reg_addr
|
||||||
|
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
|
@ -216,30 +227,35 @@ def sig_prog(proc, sig):
|
||||||
def daemon(
|
def daemon(
|
||||||
loglevel: str,
|
loglevel: str,
|
||||||
testdir,
|
testdir,
|
||||||
arb_addr: tuple[str, int],
|
reg_addr: tuple[str, int],
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Run a daemon actor as a "remote arbiter".
|
Run a daemon root actor as a separate actor-process tree and
|
||||||
|
"remote registrar" for discovery-protocol related tests.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if loglevel in ('trace', 'debug'):
|
if loglevel in ('trace', 'debug'):
|
||||||
# too much logging will lock up the subproc (smh)
|
# XXX: too much logging will lock up the subproc (smh)
|
||||||
loglevel = 'info'
|
loglevel: str = 'info'
|
||||||
|
|
||||||
cmdargs = [
|
code: str = (
|
||||||
sys.executable, '-c',
|
"import tractor; "
|
||||||
"import tractor; tractor.run_daemon([], registry_addr={}, loglevel={})"
|
"tractor.run_daemon([], registry_addrs={reg_addrs}, loglevel={ll})"
|
||||||
.format(
|
).format(
|
||||||
arb_addr,
|
reg_addrs=str([reg_addr]),
|
||||||
"'{}'".format(loglevel) if loglevel else None)
|
ll="'{}'".format(loglevel) if loglevel else None,
|
||||||
|
)
|
||||||
|
cmd: list[str] = [
|
||||||
|
sys.executable,
|
||||||
|
'-c', code,
|
||||||
]
|
]
|
||||||
kwargs = dict()
|
kwargs = {}
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
# without this, tests hang on windows forever
|
# without this, tests hang on windows forever
|
||||||
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP
|
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP
|
||||||
|
|
||||||
proc = testdir.popen(
|
proc = testdir.popen(
|
||||||
cmdargs,
|
cmd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
|
Loading…
Reference in New Issue