Streaming Fallback¶
-
Back to Testing Overview
Return to the Testing overview page with all topics.
yields and invocations show both handlers. Values that were already yielded stay.
def streaming_mapper(mapper: cqrs.RequestMap) -> None:
mapper.bind(
ExportOrders,
cqrs.RequestHandlerFallback(ExportOrdersHandler, ExportOrdersFallback),
)
async def test_stream_fallback_restarts_the_stream() -> None:
container = di.Container()
async with test_harness(container, streaming_mapper=streaming_mapper) as harness:
items = [item async for item in harness.streaming_mediator.stream(ExportOrders(batch=2))]
harness.invocations.assert_entered(ExportOrdersHandler)
harness.invocations.assert_entered(ExportOrdersFallback)
assert [item.index for item in harness.yields] == [0, 0, 1]
assert [item.index for item in items] == [0, 0, 1]
Library example: examples/testing/test_streaming.py.