Replies: 3 comments 5 replies
-
You can wait for the bus to be idle using:
You can adjust the test inactivity timeout using:
|
Beta Was this translation helpful? Give feedback.
-
It would be useful if this was documented on the MassTransit testing page https://masstransit.io/documentation/concepts/testing |
Beta Was this translation helpful? Give feedback.
-
Hi, I have somewhat of a similar issue. Saga is created by publishing one message and then later it is updated by publishing second message. What's weird is I tried to create a simple repro but couldn't reproduce it yet. My proper Saga is only transitioning to new state when receiving the event. I managed to hook up Open telemetry Activities to XUnit logging. Based on those logs it seems that the Saga would start and complete processing of the event message only after the InactivityTask was done. Using Test code _provider = new ServiceCollection()
.AddMassTransitTestHarness(cfg =>
{
cfg.AddSagaStateMachine<DemoSaga, DemoState>();
// Configures handler but this is not used in ResultsApproved phase
cfg.AddHandler<JobExecutionRequest>(ctx => ctx.RespondAsync(new JobExecutionResponse()
{
Id = Guid.NewGuid(),
JobLogicalName = ctx.Message.JobLogicalName,
Success = true
}));
})
.BuildServiceProvider(true);
_harness = _provider.GetRequiredService<ITestHarness>();
_sagaHarness = _harness.GetSagaStateMachineHarness<DemoSaga, DemoState>();
// Send first message and create saga, all goes well
// Publish second message
_testOutputHelper.WriteLine("Publising ResultsApproved");
await _harness.Bus.Publish(new ResultsApproved()
{
CorrelationId = sagaId
});
_testOutputHelper.WriteLine("Published ResultsApproved");
await _harness.InactivityTask;
_testOutputHelper.WriteLine("Inactivity Task done");
var hasMessages = await _harness.Consumed.Any<ResultsApproved>();
_testOutputHelper.WriteLine("Got consumed ResultsApproved: " + hasMessages);
// this fails
hasMessages.Should().BeTrue(); Logs
|
Beta Was this translation helpful? Give feedback.
-
Contact Details
No response
Version
8.x
On which operating system(s) are you experiencing the issue?
No response
Using which broker(s) did you encounter the issue?
No response
What are the steps required to reproduce the issue?
What is the expected behavior?
I'm using end to end testing with single mass transit test harness injected into many (WebApplicationFactory) microservices to allow them to communicate between one another. Unfortunately I'm unable to ensure that all messages were consumed before asserting the system state.
Documentation seems to show only a single message example, and completely omits possibility that there can be a hidden second message published by one of the tested microservices that the test should not directly interface with.
Is there a possibility to create
.All<>
and.All
(second one guarantees that all messages of all types published in the harness are consumed?What actually happened?
I was unable to find any info how to wait for all messages in a test harness to be consumed
Related log output, including any exceptions
No response
Link to repository that demonstrates/reproduces the issue
No response
Beta Was this translation helpful? Give feedback.
All reactions