From fa231bcc64153c2da85a7e23c196c26bb5488e5e Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Tue, 16 Mar 2021 10:54:15 +0100 Subject: [PATCH] Test case in flow example proves the previous fix works - closes #21 --- Examples/03-FlowRequestResponse/Program.cs | 2 +- .../SimpleFlowController.cs | 21 +++++++++++++++++++ Examples/ExampleLib/ExampleConsoleApp.cs | 10 +++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Examples/03-FlowRequestResponse/Program.cs b/Examples/03-FlowRequestResponse/Program.cs index edac429..50a361b 100644 --- a/Examples/03-FlowRequestResponse/Program.cs +++ b/Examples/03-FlowRequestResponse/Program.cs @@ -19,7 +19,7 @@ namespace _03_FlowRequestResponse container.Register(); - var helper = new ExampleConsoleApp(dependencyResolver); + var helper = new ExampleConsoleApp(dependencyResolver, 2); helper.Run(MainAsync); } diff --git a/Examples/03-FlowRequestResponse/SimpleFlowController.cs b/Examples/03-FlowRequestResponse/SimpleFlowController.cs index 1726e40..a5f972b 100644 --- a/Examples/03-FlowRequestResponse/SimpleFlowController.cs +++ b/Examples/03-FlowRequestResponse/SimpleFlowController.cs @@ -64,10 +64,31 @@ namespace _03_FlowRequestResponse Console.WriteLine("[SimpleFlowController] Response time: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("[SimpleFlowController] Quote: " + message.Quote); + + // Test for issue #21: Same request/response twice in flow does not continue + return flowProvider.YieldWithRequestSync( + new QuoteRequestMessage + { + Amount = 42 + }, + HandleQuoteResponse2); + + + //exampleState.Done(); + //return flowProvider.End(); + } + + + + [Continuation] + public IYieldPoint HandleQuoteResponse2(QuoteResponseMessage message) + { + Console.WriteLine("[SimpleFlowController] Quote 2: " + message.Quote); exampleState.Done(); return flowProvider.End(); } + } } diff --git a/Examples/ExampleLib/ExampleConsoleApp.cs b/Examples/ExampleLib/ExampleConsoleApp.cs index f7f4d98..6555c61 100644 --- a/Examples/ExampleLib/ExampleConsoleApp.cs +++ b/Examples/ExampleLib/ExampleConsoleApp.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using Tapeti; @@ -21,13 +22,17 @@ namespace ExampleLib public class ExampleConsoleApp { private readonly IDependencyContainer dependencyResolver; + private readonly int expectedDoneCount; + private int doneCount = 0; private readonly TaskCompletionSource doneSignal = new TaskCompletionSource(); /// Uses Tapeti's IDependencyContainer interface so you can easily switch an example to your favourite IoC container - public ExampleConsoleApp(IDependencyContainer dependencyResolver) + public ExampleConsoleApp(IDependencyContainer dependencyResolver, int expectedDoneCount = 1) { this.dependencyResolver = dependencyResolver; + this.expectedDoneCount = expectedDoneCount; + dependencyResolver.RegisterDefault(() => new ExampleState(this)); } @@ -85,7 +90,8 @@ namespace ExampleLib internal void Done() { - doneSignal.TrySetResult(true); + if (Interlocked.Increment(ref doneCount) == expectedDoneCount) + doneSignal.TrySetResult(true); }