2026-08-25 03:13:20 +00:00
|
|
|
'''
|
|
|
|
|
Shared helpers for actor-runtime test suites.
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from types import TracebackType
|
|
|
|
|
|
|
|
|
|
import tractor
|
2026-08-25 17:44:50 +00:00
|
|
|
import trio
|
2026-08-25 03:13:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CancellationMarkers:
|
|
|
|
|
'''
|
2026-08-25 17:44:50 +00:00
|
|
|
Mark a test endpoint and require cancellation-driven teardown.
|
2026-08-25 03:13:20 +00:00
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
started_path: str,
|
|
|
|
|
cancelled_path: str,
|
|
|
|
|
) -> None:
|
|
|
|
|
self.started_path = started_path
|
|
|
|
|
self.cancelled_path = cancelled_path
|
|
|
|
|
|
|
|
|
|
def __enter__(self) -> None:
|
|
|
|
|
Path(self.started_path).touch()
|
|
|
|
|
|
|
|
|
|
def __exit__(
|
|
|
|
|
self,
|
|
|
|
|
exc_type: type[BaseException]|None,
|
|
|
|
|
exc_value: BaseException|None,
|
|
|
|
|
traceback: TracebackType|None,
|
|
|
|
|
) -> None:
|
2026-08-25 17:44:50 +00:00
|
|
|
assert exc_type is trio.Cancelled
|
|
|
|
|
assert isinstance(exc_value, trio.Cancelled)
|
2026-08-25 03:13:20 +00:00
|
|
|
Path(self.cancelled_path).touch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def non_registration_contexts(
|
|
|
|
|
actor: tractor.Actor,
|
|
|
|
|
) -> dict[tuple, str]:
|
|
|
|
|
'''
|
|
|
|
|
Snapshot application contexts without registrar-service traffic.
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
return {
|
|
|
|
|
key: str(ctx._nsf)
|
|
|
|
|
for key, ctx in actor._contexts.items()
|
|
|
|
|
if str(ctx._nsf) != (
|
|
|
|
|
'tractor.discovery._registry:'
|
|
|
|
|
'Registrar.register_actor'
|
|
|
|
|
)
|
|
|
|
|
}
|