It looks like everytime I set up a Mock object to throw an exception within a Rebus SagaFixture, when the exception is thrown the bus handles retries several times. This causes async issues in the test assertions on the Saga data and Exceptions based on the state mutating after the saga was first initialized.
If you want to configure the number of delivery attempts, you can use one of the saga fixture factory methods that has a maxDeliveryAttempts
parameter, e.g. like
using var fixture = SagaFixture.For(() => new MySaga(), maxDeliveryAttempts: 1);
This test shows that the number of caught exceptions can be counted on, when setting MAX delivery attempts: https://github.com/rebus-org/Rebus.TestHelpers/blob/master/Rebus.TestHelpers.Tests/Bugs/TestAsyncConcurrencyChallengeWithSagaFixture.cs
Unfortunately, the generic factory method (e.g. SagaFixture.For<MySaga>()
) does not currently have any additional parameters, but I'll add that some time later today. 🙂
Update: Rebus.TestHelpers 7.1.1 accepts the same parameters in the generic factory method, so it's now possible to call SagaFixture.For<MySaga>(maxDeliveryAttempts: 1))