You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.2 KiB
66 lines
2.2 KiB
"""P2-015 slice 4: store-native bridge table and OBP source ops."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from adn_server.application.subscription.bridge_table_ops import (
|
|
make_single_bridge_store,
|
|
make_static_tg_store,
|
|
)
|
|
from adn_server.application.subscription.obp_source_ops import ensure_obp_source_for_tg_store
|
|
from adn_server.application.subscription.store_sync import replace_store_from_bridges
|
|
from adn_server.domain import bytes_3
|
|
from adn_server.infrastructure.subscription_store import InMemorySubscriptionStore
|
|
from tests.harness.deterministic import active_bridge, minimal_config
|
|
|
|
|
|
def _store(bridges: dict | None = None) -> InMemorySubscriptionStore:
|
|
store = InMemorySubscriptionStore()
|
|
if bridges:
|
|
replace_store_from_bridges(store, bridges)
|
|
return store
|
|
|
|
|
|
def test_make_static_tg_store_creates_active_off_leg() -> None:
|
|
config = minimal_config(("MASTER-A",))
|
|
store = _store()
|
|
make_static_tg_store(
|
|
store,
|
|
52090,
|
|
2,
|
|
10.0,
|
|
"MASTER-A",
|
|
config["SYSTEMS"],
|
|
now=1000.0,
|
|
single_mode=False,
|
|
)
|
|
leg = next(s for s in store.snapshot() if s.system.value == "MASTER-A" and int(s.channel.slot) == 2)
|
|
assert leg.is_active()
|
|
|
|
|
|
def test_ensure_obp_source_activates_ts1_leg() -> None:
|
|
bridges = active_bridge(7305, (("OBP-CL", 1), ("MASTER-A", 2)))
|
|
for entry in bridges["7305"]:
|
|
if entry["SYSTEM"] == "OBP-CL":
|
|
entry["ACTIVE"] = False
|
|
store = _store(bridges)
|
|
ensure_obp_source_for_tg_store(store, "OBP-CL", "7305", bytes_3(7305), 7305, now=500.0)
|
|
obp = next(s for s in store.snapshot() if s.system.value == "OBP-CL")
|
|
assert obp.is_active()
|
|
|
|
|
|
def test_make_single_bridge_store_obp_leg() -> None:
|
|
config = minimal_config(("MASTER-A",))
|
|
add_obp = {
|
|
"OBP-CL": {
|
|
"MODE": "OPENBRIDGE",
|
|
"ENABLED": True,
|
|
"IP": "127.0.0.1",
|
|
"PORT": 0,
|
|
}
|
|
}
|
|
config["SYSTEMS"].update(add_obp)
|
|
store = _store()
|
|
make_single_bridge_store(store, 7305, "MASTER-A", 2, 10.0, config["SYSTEMS"], now=1.0)
|
|
obp = next(s for s in store.snapshot() if s.system.value == "OBP-CL")
|
|
assert obp.is_active()
|