From 8bbb91757c02f395b30aabda4d49f85538d609fb Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Tue, 2 May 2023 18:14:04 -0500 Subject: [PATCH] Fixed #4346 - TimeoutExpired for Request in State Machine was using incorrect correlation syntax (also made annoying RMQ test Flaky) --- .../MassTransitStateMachine.cs | 4 ++-- .../Request_Specs.cs | 21 ++++++++++++++----- .../TopologyCorrelationId_Specs.cs | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/MassTransit/SagaStateMachine/MassTransitStateMachine.cs b/src/MassTransit/SagaStateMachine/MassTransitStateMachine.cs index 2c2add8b40b..b3c8b0b011d 100644 --- a/src/MassTransit/SagaStateMachine/MassTransitStateMachine.cs +++ b/src/MassTransit/SagaStateMachine/MassTransitStateMachine.cs @@ -1488,7 +1488,7 @@ protected internal void Request( }); Event(propertyExpression, x => x.TimeoutExpired, x => { - x.CorrelateById(context => context.Message.RequestId); + x.CorrelateBy(requestIdExpression, context => context.Message.RequestId); settings.TimeoutExpired?.Invoke(x); }); @@ -1664,7 +1664,7 @@ protected internal void Request( }); Event(propertyExpression, x => x.TimeoutExpired, x => { - x.CorrelateById(context => context.Message.RequestId); + x.CorrelateBy(requestIdExpression, context => context.Message.RequestId); settings.TimeoutExpired?.Invoke(x); }); diff --git a/tests/MassTransit.QuartzIntegration.Tests/Request_Specs.cs b/tests/MassTransit.QuartzIntegration.Tests/Request_Specs.cs index 5a6403b3b79..beb16a4c16f 100644 --- a/tests/MassTransit.QuartzIntegration.Tests/Request_Specs.cs +++ b/tests/MassTransit.QuartzIntegration.Tests/Request_Specs.cs @@ -91,12 +91,12 @@ protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpoin protected virtual void ConfigureServiceQueueEndpoint(IReceiveEndpointConfigurator configurator) { - configurator.Handler(async context => + configurator.Handler(context => { Console.WriteLine("Address validated: {0}", context.Message.CorrelationId); if (context.IsResponseAccepted(false)) - await context.RespondAsync(new { }); + return context.RespondAsync(new { }); throw new InvalidOperationException("Response type not accepted"); }); @@ -112,7 +112,7 @@ protected virtual void ConfigureServiceQueueEndpoint(IReceiveEndpointConfigurato class RequestSettingsImpl : - RequestSettings + RequestSettings { public RequestSettingsImpl(Uri serviceAddress, Uri schedulingServiceAddress, TimeSpan timeout) { @@ -128,6 +128,7 @@ public RequestSettingsImpl(Uri serviceAddress, Uri schedulingServiceAddress, Tim public TimeSpan Timeout { get; } public TimeSpan? TimeToLive { get; } public Action> Completed { get; set; } + public Action> Completed2 { get; set; } public Action>> Faulted { get; set; } public Action>> TimeoutExpired { get; set; } } @@ -180,6 +181,15 @@ public interface AddressValidated : } + public interface AddressInvalidated : + CorrelatedBy + { + string Address { get; } + + string RequestAddress { get; } + } + + public interface ValidateName : CorrelatedBy { @@ -199,7 +209,7 @@ public interface NameValidated : class TestStateMachine : MassTransitStateMachine { - public TestStateMachine(RequestSettings settings) + public TestStateMachine(RequestSettings settings) { Event(() => Register, x => { @@ -261,7 +271,8 @@ public TestStateMachine(RequestSettings await Console.Out.WriteLineAsync("Request timed out")) .TransitionTo(NameValidationTimeout)); } // ReSharper disable UnassignedGetOnlyAutoProperty - public Request ValidateAddress { get; } + + public Request ValidateAddress { get; } public Request ValidateName { get; } public Event Register { get; } diff --git a/tests/MassTransit.RabbitMqTransport.Tests/TopologyCorrelationId_Specs.cs b/tests/MassTransit.RabbitMqTransport.Tests/TopologyCorrelationId_Specs.cs index ded0a800529..9618de8de06 100644 --- a/tests/MassTransit.RabbitMqTransport.Tests/TopologyCorrelationId_Specs.cs +++ b/tests/MassTransit.RabbitMqTransport.Tests/TopologyCorrelationId_Specs.cs @@ -6,6 +6,7 @@ namespace MassTransit.RabbitMqTransport.Tests [TestFixture] + [Category("Flaky")] public class When_using_a_name_property_for_correlation : RabbitMqTestFixture { @@ -76,6 +77,7 @@ public class LegacyMessage [TestFixture] + [Category("Flaky")] public class When_using_a_base_event : RabbitMqTestFixture {