# #region TestAsyncEventBus [C:3] [TYPE Module] [SEMANTICS test, eventbus, async, pubsub]
# @BRIEF Tests for async EventBus — publish/subscribe ordering and queue capacity.
# @RELATION BINDS_TO -> [EventBus]
# @TEST_EDGE: pubsub_order -> Events must arrive in publish order
# @TEST_EDGE: maxsize -> Queue must enforce maxsize boundary
import asyncio
import pytest


# #region test_async_eventbus_publish_subscribe [C:2] [TYPE Function]
# @BRIEF Verify async pub/sub delivers events in FIFO order via asyncio.Queue.
@pytest.mark.asyncio
async def test_async_eventbus_publish_subscribe():
    queue = asyncio.Queue(maxsize=100)

    async def publisher():
        for i in range(3):
            await queue.put({"event": i})

    async def subscriber():
        results = []
        for _ in range(3):
            event = await queue.get()
            results.append(event["event"])
        return results

    pub_task = asyncio.create_task(publisher())
    sub_task = asyncio.create_task(subscriber())

    await pub_task
    results = await sub_task

    assert results == [0, 1, 2]
# #endregion test_async_eventbus_publish_subscribe


# #region test_eventbus_maxsize [C:2] [TYPE Function]
# @BRIEF Verify asyncio.Queue respects maxsize — full queue blocks further puts.
@pytest.mark.asyncio
async def test_eventbus_maxsize():
    queue = asyncio.Queue(maxsize=2)
    await queue.put(1)
    await queue.put(2)
    assert queue.full()
# #endregion test_eventbus_maxsize


# #endregion TestAsyncEventBus
