Saga Fallback¶
-
Back to Testing Overview
Return to the Testing overview page with all topics.
Both classes are on invocations. The last method of ReserveStock is act, not compensate, and the saga is COMPLETED. This is not compensation.
class OrderSaga(cqrs.Saga[OrderContext]):
steps = [
cqrs.saga.fallback.Fallback(step=ReserveStock, fallback=ReserveStockFallback),
ChargeCard,
]
async def test_saga_fallback_replaces_the_failed_step() -> None:
container = di.Container()
async with test_harness(container, sagas_mapper=sagas_mapper) as harness:
async for _ in harness.saga_mediator.execute(OrderContext(order_id="1")):
pass
harness.invocations.assert_entered(ReserveStock)
harness.invocations.assert_entered(ReserveStockFallback)
assert harness.invocations.of(ReserveStock)[-1].method == "act"
assert harness.sagas.one(OrderSaga).status is SagaStatus.COMPLETED
Library example: examples/testing/test_saga.py.