Fix work recovery and reduce engine and chart overhead
Docs / docs (push) Successful in 33s
Playwright Tests / test-playwright (1, 2) (push) Failing after 1m37s
Playwright Tests / test-playwright (2, 2) (push) Failing after 27s
pre-commit / pre-commit (push) Failing after 2m37s
Test Backend / test-backend (3.12) (push) Successful in 5m7s
Test Backend / test-backend (3.14) (push) Successful in 5m2s
Compose Smoke Test / test-compose (push) Failing after 28s
Playwright Tests / merge-reports (push) Failing after 2m29s

This commit is contained in:
2026-10-29 14:24:17 +01:00
parent 20a0853f69
commit 75b3a93094
25 changed files with 1316 additions and 301 deletions
+92 -1
View File
@@ -2,8 +2,11 @@
import asyncio
import threading
from contextlib import AsyncExitStack
from fluksio.flow.events import QUEUE_SIZE, EventBus
import pytest
from fluksio.flow.events import DISPATCH_BUDGET, QUEUE_SIZE, EventBus
def _event(i: int) -> dict[str, object]:
@@ -100,3 +103,91 @@ def test_nothing_is_buffered_with_nobody_listening() -> None:
return len(bus._pending)
assert asyncio.run(run()) == 0
@pytest.mark.parametrize("flush", [False, True])
def test_overflow_keeps_errors_and_control_events_in_order(flush: bool) -> None:
"""The staging bound and a slow subscriber use the same eviction policy."""
async def run() -> None:
bus = EventBus()
bus.bind(asyncio.get_running_loop())
critical = [
{"type": "node_log", "level": "error"},
{"type": "node_error"},
{"type": "run_started"},
{"type": "audit"},
{"type": "dashboard_changed"},
{"type": "future_control_event"},
]
async with bus.subscribe() as first, bus.subscribe() as second:
sent = [*critical, *(_event(i) for i in range(QUEUE_SIZE + 50))]
sent.append({"type": "run_finished"})
for sequence, event in enumerate(sent):
event["sequence"] = sequence
bus.publish(event)
assert len(bus._pending) <= QUEUE_SIZE
if flush:
# Queue overflow, with no staging overflow.
await asyncio.sleep(0)
await asyncio.sleep(0)
for queue in (first, second):
received = [queue.get_nowait() for _ in range(queue.qsize())]
assert len(received) == QUEUE_SIZE
assert received[: len(critical)] == critical
assert received[-1]["type"] == "run_finished"
assert received == sorted(received, key=lambda e: e["sequence"])
assert bus.dropped(queue)
assert not bus.dropped(queue)
asyncio.run(run())
def test_a_full_critical_backlog_rejects_telemetry_and_reports_loss() -> None:
async def run() -> None:
bus = EventBus()
bus.bind(asyncio.get_running_loop())
async with bus.subscribe() as queue:
for i in range(QUEUE_SIZE + 1):
bus.publish({"type": "node_error", "sequence": i})
bus.publish(_event(0))
assert len(bus._pending) == QUEUE_SIZE
await asyncio.sleep(0)
assert bus.dropped(queue)
assert (await queue.get())["sequence"] == 1
bus.publish({"type": "audit"})
await asyncio.sleep(0)
bus.publish(_event(1))
await asyncio.sleep(0)
assert bus.dropped(queue)
assert queue.qsize() == QUEUE_SIZE
assert all(
queue.get_nowait()["type"] != "node_executed" for _ in range(QUEUE_SIZE)
)
asyncio.run(run())
def test_fanout_yields_before_all_subscribers_are_served() -> None:
async def run() -> None:
bus = EventBus()
loop = asyncio.get_running_loop()
bus.bind(loop)
async with AsyncExitStack() as stack:
queues = [
await stack.enter_async_context(bus.subscribe())
for _ in range(DISPATCH_BUDGET // QUEUE_SIZE + 1)
]
for i in range(QUEUE_SIZE):
bus.publish(_event(i))
heartbeat: asyncio.Future[int] = loop.create_future()
loop.call_soon(
lambda: heartbeat.set_result(sum(queue.qsize() for queue in queues))
)
assert await heartbeat == DISPATCH_BUDGET
await asyncio.sleep(0)
assert all(queue.qsize() == QUEUE_SIZE for queue in queues)
assert not any(bus.dropped(queue) for queue in queues)
assert not bus._flush_scheduled
asyncio.run(run())