Compare commits

..

3 Commits

Author SHA1 Message Date
Gud Boi d89ece08e4 Derive transport registries from one list
The five transport/address lookup maps each hand-guarded `uds`
with its own `if HAS_UDS:` block (3 in `ipc/_types`, 2 in
`discovery/_addr`) — easy to let drift so a backend half-registers
(known by address but not by key, listed but unroutable, &c).

- build one `_msg_transports` / `_address_protos` list per module
  (TCP always, UDS only when `HAS_UDS`), then DERIVE every map
  from it via each backend's ClassVars (`codec_key`,
  `address_type`, `proto_key`). Adding a backend now touches one
  list, and the maps can't disagree.

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-06-30 02:46:00 -04:00
Gud Boi 7ae8ddfb2c Skip `infect_asyncio` tests on Windows
`tractor`'s infect-asyncio mode runs an `asyncio` loop under
`trio` guest-mode; on Windows the default `ProactorEventLoop` is
incompatible and the suite hangs/crashes mid-run (orphaned py
procs), so the `windows-latest` CI leg never finishes reporting.

- add a module-level `pytest.skip(allow_module_level=True)` gated
  on `platform.system() == 'Windows'` to `test_infected_asyncio`
  and `test_root_infect_asyncio`, before their asyncio-interop
  imports. macOS/linux are unaffected (they run these fine).

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-06-30 02:45:50 -04:00
Gud Boi 9f36e743a9 Scale `test_lifetime_stack` deadline for CI
`test_lifetime_stack_wipes_tmpfile` guards spawn+teardown with a
hard-coded `trio.move_on_after()` (1.6s / 1s) that isn't scaled
for slow CI. On a noisy macOS runner the `error_in_child=True`
case times out before the child error propagates, so the scope
cancels and `assert not cs.cancel_called` flips — reddening the
(required) macOS leg. Same unscaled-deadline class `main` already
fixed for `test_dynamic_pub_sub`.

- multiply the budget by `cpu_perf_headroom()` (`tests/conftest`),
  the established deadline-headroom helper (3x on macOS CI, a
  1.0 no-op locally / on un-throttled linux).

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-06-30 02:45:23 -04:00
5 changed files with 70 additions and 21 deletions

View File

@ -20,6 +20,18 @@ from typing import (
import pytest
import trio
import tractor
# `infect_asyncio` mode is unsupported on Windows (asyncio's
# `ProactorEventLoop` is incompatible with our `trio` guest-mode
# interop and currently hangs/crashes the run). Skip the module on
# Windows so the CI leg completes + reports the rest of the suite.
import platform
if platform.system() == 'Windows':
pytest.skip(
'infect_asyncio mode is unsupported on Windows',
allow_module_level=True,
)
from tractor import (
current_actor,
Actor,

View File

@ -9,6 +9,17 @@ from functools import partial
import pytest
import trio
import tractor
# `infect_asyncio` mode is unsupported on Windows (see
# `test_infected_asyncio`); skip at COLLECTION before the
# asyncio-interop imports below so the CI leg completes.
import platform
if platform.system() == 'Windows':
pytest.skip(
'infect_asyncio mode is unsupported on Windows',
allow_module_level=True,
)
from tractor import (
to_asyncio,
)

View File

@ -73,6 +73,11 @@ async def test_lifetime_stack_wipes_tmpfile(
1.6 if error_in_child
else 1
)
# scale for slow/noisy CI (esp. macOS) so the child error
# propagates before the deadline; otherwise `move_on_after`
# cancels first and flips the `error_in_child=True` assert.
from .conftest import cpu_perf_headroom
timeout *= cpu_perf_headroom()
try:
with trio.move_on_after(timeout) as cs:
async with tractor.open_nursery(

View File

@ -172,24 +172,36 @@ class Address(Protocol):
...
_address_types: bidict[str, Type[Address]] = {
'tcp': TCPAddress,
}
# the address types available on this host: TCP always, UDS only
# where usable (`HAS_UDS`). Both registries derive from this single
# list via each type's `proto_key`.
_address_protos: list[Type[Address]] = [TCPAddress]
if HAS_UDS:
_address_types['uds'] = UDSAddress
_address_protos.append(UDSAddress)
_address_types: bidict[str, Type[Address]] = bidict({
cls.proto_key: cls
for cls in _address_protos
})
# TODO! really these are discovery sys default addrs ONLY useful for
# when none is provided to a root actor on first boot.
_default_lo_addrs: dict[str, UnwrappedAddress] = {
'tcp': TCPAddress.get_root().unwrap(),
cls.proto_key: cls.get_root().unwrap()
for cls in _address_protos
}
if HAS_UDS:
_default_lo_addrs['uds'] = UDSAddress.get_root().unwrap()
def get_address_cls(name: str) -> Type[Address]:
return _address_types[name]
try:
return _address_types[name]
except KeyError:
raise NotImplementedError(
f'No IPC transport backend for {name!r} on this '
f'platform!\n'
f'(available: {list(_address_types)})\n'
)
def is_wrapped_addr(addr: any) -> bool:
@ -287,7 +299,14 @@ def default_lo_addrs(
for an input transport key set.
'''
return [
_default_lo_addrs[transport]
for transport in transports
]
lo_addrs: list[UnwrappedAddress] = []
for transport in transports:
try:
lo_addrs.append(_default_lo_addrs[transport])
except KeyError:
raise NotImplementedError(
f'No default loopback addr for transport '
f'{transport!r} on this platform!\n'
f'(available: {list(_default_lo_addrs)})\n'
)
return lo_addrs

View File

@ -41,26 +41,28 @@ from tractor.ipc._uds import (
# hosts `HAS_UDS` is `False` and the runtime registers TCP only.
Address = TCPAddress|UDSAddress
# manually updated list of all supported msg transport types
# the available msg-transport backends on this host: TCP always,
# UDS only where usable (`HAS_UDS`). The lookup maps below are all
# DERIVED from this single list via each backend's ClassVars
# (`codec_key`, `address_type`) — register a backend here and every
# map picks it up; no per-map `if HAS_UDS` to keep in sync.
_msg_transports: list[Type[MsgTransport]] = [
MsgpackTCPStream,
]
if HAS_UDS:
_msg_transports.append(MsgpackUDSStream)
# map a `MsgTransportKey` to its `MsgTransport` type
# map a `MsgTransportKey` -> `MsgTransport` type
_key_to_transport: dict[MsgTransportKey, Type[MsgTransport]] = {
('msgpack', 'tcp'): MsgpackTCPStream,
(t.codec_key, t.address_type.proto_key): t
for t in _msg_transports
}
if HAS_UDS:
_key_to_transport[('msgpack', 'uds')] = MsgpackUDSStream
# map an `Address`-wrapper to its `MsgTransport` type
# map an `Address`-wrapper -> `MsgTransport` type
_addr_to_transport: dict[Type[Address], Type[MsgTransport]] = {
TCPAddress: MsgpackTCPStream,
t.address_type: t
for t in _msg_transports
}
if HAS_UDS:
_addr_to_transport[UDSAddress] = MsgpackUDSStream
# ------------------------------------------------------------