From ac934e24df6f60fc5bea82a65a0c3ed8c8b41d9a Mon Sep 17 00:00:00 2001 From: Naiyuan Tian <110135109+nytian@users.noreply.github.com> Date: Tue, 30 Apr 2024 10:41:27 -0700 Subject: [PATCH 1/9] Update TaskEntityDispatcher.cs --- src/DurableTask.Core/TaskEntityDispatcher.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index 8e6dd7d8d..4ed0d7447 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -801,8 +801,8 @@ void ProcessSendStartMessage(WorkItemEffects effects, OrchestrationRuntimeState var executionStartedEvent = new ExecutionStartedEvent(-1, action.Input) { Tags = OrchestrationTags.MergeTags( - runtimeState.Tags, - new Dictionary() { { OrchestrationTags.FireAndForget, "" } }), + new Dictionary() { { OrchestrationTags.FireAndForget, "" } }, + runtimeState.Tags), OrchestrationInstance = destination, ScheduledStartTime = action.ScheduledStartTime, ParentInstance = new ParentInstance @@ -881,4 +881,4 @@ await this.dispatchPipeline.RunAsync(dispatchContext, async _ => return result; } } -} \ No newline at end of file +} From 1f18438a234e096ebe886859e279cbfab3dfd115 Mon Sep 17 00:00:00 2001 From: "naiyuantian@microsoft.com" Date: Thu, 2 May 2024 11:07:15 -0700 Subject: [PATCH 2/9] update by comment --- src/DurableTask.Core/TaskEntityDispatcher.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index 4ed0d7447..747c5247e 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -563,6 +563,11 @@ void DetermineWork(OrchestrationRuntimeState runtimeState, out SchedulerState sc } break; + + default: + { + throw new EntitySchedulerException($"Unexpected event type {e.EventType} in entity scheduler history."); + } } } @@ -801,8 +806,8 @@ void ProcessSendStartMessage(WorkItemEffects effects, OrchestrationRuntimeState var executionStartedEvent = new ExecutionStartedEvent(-1, action.Input) { Tags = OrchestrationTags.MergeTags( - new Dictionary() { { OrchestrationTags.FireAndForget, "" } }, - runtimeState.Tags), + newTags: new Dictionary() { { OrchestrationTags.FireAndForget, "" } }, + existingTags: runtimeState.Tags), OrchestrationInstance = destination, ScheduledStartTime = action.ScheduledStartTime, ParentInstance = new ParentInstance From aea813b3f5b99c1679641dee67906fa83cfee7b0 Mon Sep 17 00:00:00 2001 From: "naiyuantian@microsoft.com" Date: Thu, 2 May 2024 11:09:24 -0700 Subject: [PATCH 3/9] remove brackets --- src/DurableTask.Core/TaskEntityDispatcher.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index 747c5247e..af81d0f20 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -565,9 +565,7 @@ void DetermineWork(OrchestrationRuntimeState runtimeState, out SchedulerState sc break; default: - { throw new EntitySchedulerException($"Unexpected event type {e.EventType} in entity scheduler history."); - } } } From 34190ee8a836d0afae28e38ccc491a121cf00d0e Mon Sep 17 00:00:00 2001 From: "naiyuantian@microsoft.com" Date: Thu, 2 May 2024 11:09:52 -0700 Subject: [PATCH 4/9] remove white space --- src/DurableTask.Core/TaskEntityDispatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index af81d0f20..0304d8e16 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -565,7 +565,7 @@ void DetermineWork(OrchestrationRuntimeState runtimeState, out SchedulerState sc break; default: - throw new EntitySchedulerException($"Unexpected event type {e.EventType} in entity scheduler history."); + throw new EntitySchedulerException($"Unexpected event type {e.EventType} in entity scheduler history."); } } From 41e9ea6ab9de048233274788b9c4d1b00a29dc10 Mon Sep 17 00:00:00 2001 From: "naiyuantian@microsoft.com" Date: Fri, 3 May 2024 11:14:46 -0700 Subject: [PATCH 5/9] add unit test --- .../TestEntityDispatcher.cs | 40 ++++++++++++++ .../Entities/EntityTestHelper.cs | 55 +++++++++++++++++++ src/DurableTask.Core/TaskEntityDispatcher.cs | 40 ++++++++++++-- 3 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs create mode 100644 src/DurableTask.Core/Entities/EntityTestHelper.cs diff --git a/Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs b/Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs new file mode 100644 index 000000000..ac9b909cb --- /dev/null +++ b/Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs @@ -0,0 +1,40 @@ +using DurableTask.Core; +using DurableTask.Core.Entities; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using DurableTask.Core.Logging; +using DurableTask.Core.Entities.OperationFormat; +using System.Text; +using Microsoft.Extensions.Azure; +using DurableTask.Core.History; + +namespace DurableTask.AzureStorage.Tests +{ + [TestClass] + public class TestEntityDispatcher + { + readonly string connection = TestHelpers.GetTestStorageAccountConnectionString(); + + + [TestMethod] + public void TestScheduleOrchestration() + { + var settings = new AzureStorageOrchestrationServiceSettings() + { + StorageConnectionString = this.connection, + TaskHubName = "EntityScheduleOrch", + }; + var service = new AzureStorageOrchestrationService(settings); + var entityTestHelper = new EntityTestHelper(service); + var testEvent = entityTestHelper.TestScheduleOrchestrationTags(); + + Assert.IsInstanceOfType(testEvent, typeof(ExecutionStartedEvent)); + var testEventTags = (ExecutionStartedEvent)testEvent; + bool containsKey = testEventTags.Tags.ContainsKey(OrchestrationTags.FireAndForget); + Assert.IsTrue(containsKey); + } + + } +} diff --git a/src/DurableTask.Core/Entities/EntityTestHelper.cs b/src/DurableTask.Core/Entities/EntityTestHelper.cs new file mode 100644 index 000000000..985c4ccd5 --- /dev/null +++ b/src/DurableTask.Core/Entities/EntityTestHelper.cs @@ -0,0 +1,55 @@ +using DurableTask.Core.History; +using DurableTask.Core.Logging; +using DurableTask.Core.Middleware; +using Microsoft.Extensions.Logging; + +namespace DurableTask.Core.Entities +{ + /// + /// Class to help test TaskEntityDispatcher. + /// + public class EntityTestHelper + { + IOrchestrationService orchestrationService; + TaskEntityDispatcher dispatcher; + + /// + /// Constructor for EntityTestHelper + /// + /// The for initialize TaskEntityDispatcher instance. + public EntityTestHelper(IOrchestrationService service) + { + this.orchestrationService = service; + this.dispatcher ??= CreateTestEntityDispatcherInstance(); + } + + /// + /// Create a instance of the TaskEntityDispatcher class for testing. + /// + /// Instance created for testing. + public TaskEntityDispatcher CreateTestEntityDispatcherInstance() + { + ILoggerFactory loggerFactory = null; + var entityManager = new NameVersionObjectManager(); + var entityMiddleware = new DispatchMiddlewarePipeline(); + var logger = new LogHelper(loggerFactory?.CreateLogger("DurableTask.Core")); + + return new TaskEntityDispatcher + ( + this.orchestrationService, + entityManager, + entityMiddleware, + logger, + ErrorPropagationMode.SerializeExceptions); + } + + /// + /// Method to test orchestration settings when entities schedule it. + /// + /// HistoryEvent contains the schedule message. + public HistoryEvent TestScheduleOrchestrationTags() + { + return this.dispatcher.TestScheduleSendEvent(); + } + } +} diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index 0304d8e16..26aae05a6 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -12,11 +12,6 @@ // ---------------------------------------------------------------------------------- namespace DurableTask.Core { - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Threading; - using System.Threading.Tasks; using DurableTask.Core.Common; using DurableTask.Core.Entities; using DurableTask.Core.Entities.EventFormat; @@ -27,6 +22,11 @@ namespace DurableTask.Core using DurableTask.Core.Middleware; using DurableTask.Core.Tracing; using Newtonsoft.Json; + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Threading; + using System.Threading.Tasks; /// /// Dispatcher for orchestrations and entities to handle processing and renewing, completion of orchestration events. @@ -883,5 +883,35 @@ await this.dispatchPipeline.RunAsync(dispatchContext, async _ => return result; } + + /// + /// Test only. + /// + public HistoryEvent TestScheduleSendEvent() + { + // Initialize arguments to pass to ProcessSendStartMessage(). + var effects = new WorkItemEffects(); + effects.taskIdCounter = 0; + effects.InstanceMessages = new List(); + + var mockEntityStartEvent = new ExecutionStartedEvent(-1, null) + { + OrchestrationInstance = new OrchestrationInstance(), + Name = "testentity", + Version = "1.0", + }; + var runtimeState = new OrchestrationRuntimeState(); + runtimeState.AddEvent(mockEntityStartEvent); + var action = new StartNewOrchestrationOperationAction() + { + InstanceId = "testsample", + Name = "test", + Version = "1.0", + Input = null, + }; + + this.ProcessSendStartMessage(effects, runtimeState,action); + return effects.InstanceMessages[0].Event; + } } } From cd2c7e5914496d1071d3a9bccb361408a85d0b24 Mon Sep 17 00:00:00 2001 From: "naiyuantian@microsoft.com" Date: Fri, 3 May 2024 11:16:47 -0700 Subject: [PATCH 6/9] update error msg --- src/DurableTask.Core/TaskEntityDispatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index 26aae05a6..e9aaf044a 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -565,7 +565,7 @@ void DetermineWork(OrchestrationRuntimeState runtimeState, out SchedulerState sc break; default: - throw new EntitySchedulerException($"Unexpected event type {e.EventType} in entity scheduler history."); + throw new EntitySchedulerException($"The entity with instanceId '{instanceId}' received an unexpected event type of type '{e.EventType}'. This is not a valid entity message. This is a framework-internal error, please report this issue in the GitHub repo: 'https://github.com/Azure/durabletask/'"); } } From 1e5f4d506fdb978b97e2101f0df28611c921a2e2 Mon Sep 17 00:00:00 2001 From: "naiyuantian@microsoft.com" Date: Mon, 6 May 2024 19:41:43 -0700 Subject: [PATCH 7/9] update unit test --- .../TestEntityDispatcher.cs | 40 ------------------- .../TestTaskEntityDispatcher.cs | 25 ++++++++++++ .../Entities/EntityTestHelper.cs | 6 +-- src/DurableTask.Core/TaskEntityDispatcher.cs | 2 +- .../LocalOrchestrationService.cs | 34 +++++++++++++++- 5 files changed, 62 insertions(+), 45 deletions(-) delete mode 100644 Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs create mode 100644 Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs diff --git a/Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs b/Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs deleted file mode 100644 index ac9b909cb..000000000 --- a/Test/DurableTask.AzureStorage.Tests/TestEntityDispatcher.cs +++ /dev/null @@ -1,40 +0,0 @@ -using DurableTask.Core; -using DurableTask.Core.Entities; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; -using DurableTask.Core.Logging; -using DurableTask.Core.Entities.OperationFormat; -using System.Text; -using Microsoft.Extensions.Azure; -using DurableTask.Core.History; - -namespace DurableTask.AzureStorage.Tests -{ - [TestClass] - public class TestEntityDispatcher - { - readonly string connection = TestHelpers.GetTestStorageAccountConnectionString(); - - - [TestMethod] - public void TestScheduleOrchestration() - { - var settings = new AzureStorageOrchestrationServiceSettings() - { - StorageConnectionString = this.connection, - TaskHubName = "EntityScheduleOrch", - }; - var service = new AzureStorageOrchestrationService(settings); - var entityTestHelper = new EntityTestHelper(service); - var testEvent = entityTestHelper.TestScheduleOrchestrationTags(); - - Assert.IsInstanceOfType(testEvent, typeof(ExecutionStartedEvent)); - var testEventTags = (ExecutionStartedEvent)testEvent; - bool containsKey = testEventTags.Tags.ContainsKey(OrchestrationTags.FireAndForget); - Assert.IsTrue(containsKey); - } - - } -} diff --git a/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs b/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs new file mode 100644 index 000000000..13c886baa --- /dev/null +++ b/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs @@ -0,0 +1,25 @@ +using DurableTask.Core.Entities; +using DurableTask.Core.History; +using DurableTask.Emulator; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace DurableTask.Core.Tests +{ + [TestClass] + public class TestTaskEntityDispatcher + { + [TestMethod] + public void TestScheduleOrchestration() + { + var service = new LocalOrchestrationService(); + + var entityTestHelper = new EntityTestHelper(service); + var testEvent = entityTestHelper.TestScheduleOrchestrationTags(); + + Assert.IsInstanceOfType(testEvent, typeof(ExecutionStartedEvent)); + var testEventTags = (ExecutionStartedEvent)testEvent; + bool containsKey = testEventTags.Tags.ContainsKey(OrchestrationTags.FireAndForget); + Assert.IsTrue(containsKey); + } + } +} diff --git a/src/DurableTask.Core/Entities/EntityTestHelper.cs b/src/DurableTask.Core/Entities/EntityTestHelper.cs index 985c4ccd5..a717ae20f 100644 --- a/src/DurableTask.Core/Entities/EntityTestHelper.cs +++ b/src/DurableTask.Core/Entities/EntityTestHelper.cs @@ -20,11 +20,11 @@ public class EntityTestHelper public EntityTestHelper(IOrchestrationService service) { this.orchestrationService = service; - this.dispatcher ??= CreateTestEntityDispatcherInstance(); + this.dispatcher = CreateTestEntityDispatcherInstance(); } /// - /// Create a instance of the TaskEntityDispatcher class for testing. + /// Create an instance of the TaskEntityDispatcher class for testing. /// /// Instance created for testing. public TaskEntityDispatcher CreateTestEntityDispatcherInstance() @@ -46,7 +46,7 @@ public TaskEntityDispatcher CreateTestEntityDispatcherInstance() /// /// Method to test orchestration settings when entities schedule it. /// - /// HistoryEvent contains the schedule message. + /// HistoryEvent contains the scheduled message. public HistoryEvent TestScheduleOrchestrationTags() { return this.dispatcher.TestScheduleSendEvent(); diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index e9aaf044a..f04843566 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -887,7 +887,7 @@ await this.dispatchPipeline.RunAsync(dispatchContext, async _ => /// /// Test only. /// - public HistoryEvent TestScheduleSendEvent() + internal HistoryEvent TestScheduleSendEvent() { // Initialize arguments to pass to ProcessSendStartMessage(). var effects = new WorkItemEffects(); diff --git a/src/DurableTask.Emulator/LocalOrchestrationService.cs b/src/DurableTask.Emulator/LocalOrchestrationService.cs index a8781df09..1331299ce 100644 --- a/src/DurableTask.Emulator/LocalOrchestrationService.cs +++ b/src/DurableTask.Emulator/LocalOrchestrationService.cs @@ -25,11 +25,12 @@ namespace DurableTask.Emulator using System.Text; using System.Threading; using System.Threading.Tasks; + using DurableTask.Core.Entities; /// /// Fully functional in-proc orchestration service for testing /// - public class LocalOrchestrationService : IOrchestrationService, IOrchestrationServiceClient, IDisposable + public class LocalOrchestrationService : IOrchestrationService, IOrchestrationServiceClient, IEntityOrchestrationService, IDisposable { // ReSharper disable once NotAccessedField.Local Dictionary sessionState; @@ -669,5 +670,36 @@ void Dispose(bool disposing) this.cancellationTokenSource.Dispose(); } } + + /// + /// Test only for core entities. The value is set as default. + EntityBackendProperties IEntityOrchestrationService.EntityBackendProperties => new EntityBackendProperties() + { + EntityMessageReorderWindow = TimeSpan.FromMinutes(30), + MaxEntityOperationBatchSize = null, + MaxConcurrentTaskEntityWorkItems = 100, + SupportsImplicitEntityDeletion = false, // not supported by this backend + MaximumSignalDelayTime = TimeSpan.FromDays(6), + UseSeparateQueueForEntityWorkItems = false, + }; + + /// + EntityBackendQueries IEntityOrchestrationService.EntityBackendQueries => null; + + /// + Task IEntityOrchestrationService.LockNextEntityWorkItemAsync( + TimeSpan receiveTimeout, + CancellationToken cancellationToken) + { + return this.LockNextTaskOrchestrationWorkItemAsync(receiveTimeout, cancellationToken); + } + + /// + Task IEntityOrchestrationService.LockNextOrchestrationWorkItemAsync( + TimeSpan receiveTimeout, + CancellationToken cancellationToken) + { + return this.LockNextTaskOrchestrationWorkItemAsync(receiveTimeout, cancellationToken); + } } } From fcfe020714ef63de989faa8a822baf4e1a54929e Mon Sep 17 00:00:00 2001 From: David Justo Date: Tue, 7 May 2024 17:18:27 -0700 Subject: [PATCH 8/9] entity tags patch (#1086) --- .../TestTaskEntityDispatcher.cs | 79 +++++++++++++++++-- .../Entities/EntityTestHelper.cs | 55 ------------- src/DurableTask.Core/TaskEntityDispatcher.cs | 34 +------- .../DurableTask.SqlServer.Tests.csproj | 2 +- 4 files changed, 74 insertions(+), 96 deletions(-) delete mode 100644 src/DurableTask.Core/Entities/EntityTestHelper.cs diff --git a/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs b/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs index 13c886baa..42cc0b2c9 100644 --- a/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs +++ b/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs @@ -1,25 +1,88 @@ using DurableTask.Core.Entities; +using DurableTask.Core.Entities.OperationFormat; using DurableTask.Core.History; +using DurableTask.Core.Logging; +using DurableTask.Core.Middleware; using DurableTask.Emulator; +using DurableTask.Test.Orchestrations; +using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using static DurableTask.Core.TaskEntityDispatcher; namespace DurableTask.Core.Tests { [TestClass] public class TestTaskEntityDispatcher { + /// + /// Utiliy function to create a TaskEntityDispatcher instance. To be expanded upon as per testing needs. + /// + /// + private TaskEntityDispatcher GetTaskEntityDispatcher() + { + // TODO: these should probably be injectable parameters to this method, + // initialized with sensible defaults if not provided + var service = new LocalOrchestrationService(); + ILoggerFactory loggerFactory = null; + var entityManager = new NameVersionObjectManager(); + var entityMiddleware = new DispatchMiddlewarePipeline(); + var logger = new LogHelper(loggerFactory?.CreateLogger("DurableTask.Core")); + + TaskEntityDispatcher dispatcher = new TaskEntityDispatcher( + service, entityManager, entityMiddleware, logger, ErrorPropagationMode.UseFailureDetails); + return dispatcher; + } + + /// + /// See: https://github.com/Azure/durabletask/pull/1080 + /// This test is motivated by a regression where Entities + /// that scheduled sub-orchestrators would incorrectly set + /// the FireAndForget tag on the ExecutionStartedEvent, causing + /// them to then receive a SubOrchestrationCompleted event, which + /// they did not know how to handle. Eventually, this led to them deleting + /// their own state. This test checks against that case. + /// [TestMethod] - public void TestScheduleOrchestration() + public void TestEntityDoesNotSetFireAndForgetTags() { - var service = new LocalOrchestrationService(); + TaskEntityDispatcher dispatcher = GetTaskEntityDispatcher(); + + // Prepare effects + var effects = new WorkItemEffects(); + effects.taskIdCounter = 0; + effects.InstanceMessages = new List(); + + // Prepare runtime state + var mockEntityStartEvent = new ExecutionStartedEvent(-1, null) + { + OrchestrationInstance = new OrchestrationInstance(), + Name = "testentity", + Version = "1.0", + }; + var runtimeState = new OrchestrationRuntimeState(); + runtimeState.AddEvent(mockEntityStartEvent); + + // Prepare action. + // This mocks starting a new orchestration from an entity. + var action = new StartNewOrchestrationOperationAction() + { + InstanceId = "testsample", + Name = "test", + Version = "1.0", + Input = null, + }; + + // Invoke the dispatcher and obtain resulting event + dispatcher.ProcessSendStartMessage(effects, runtimeState, action); + HistoryEvent resultEvent = effects.InstanceMessages[0].Event; - var entityTestHelper = new EntityTestHelper(service); - var testEvent = entityTestHelper.TestScheduleOrchestrationTags(); + Assert.IsInstanceOfType(resultEvent, typeof(ExecutionStartedEvent)); + var executionStartedEvent = (ExecutionStartedEvent)resultEvent; - Assert.IsInstanceOfType(testEvent, typeof(ExecutionStartedEvent)); - var testEventTags = (ExecutionStartedEvent)testEvent; - bool containsKey = testEventTags.Tags.ContainsKey(OrchestrationTags.FireAndForget); - Assert.IsTrue(containsKey); + // The resulting event should not contain a fire and forget tag + bool hasFireAndForgetTag = executionStartedEvent.Tags.ContainsKey(OrchestrationTags.FireAndForget); + Assert.IsFalse(hasFireAndForgetTag); } } } diff --git a/src/DurableTask.Core/Entities/EntityTestHelper.cs b/src/DurableTask.Core/Entities/EntityTestHelper.cs deleted file mode 100644 index a717ae20f..000000000 --- a/src/DurableTask.Core/Entities/EntityTestHelper.cs +++ /dev/null @@ -1,55 +0,0 @@ -using DurableTask.Core.History; -using DurableTask.Core.Logging; -using DurableTask.Core.Middleware; -using Microsoft.Extensions.Logging; - -namespace DurableTask.Core.Entities -{ - /// - /// Class to help test TaskEntityDispatcher. - /// - public class EntityTestHelper - { - IOrchestrationService orchestrationService; - TaskEntityDispatcher dispatcher; - - /// - /// Constructor for EntityTestHelper - /// - /// The for initialize TaskEntityDispatcher instance. - public EntityTestHelper(IOrchestrationService service) - { - this.orchestrationService = service; - this.dispatcher = CreateTestEntityDispatcherInstance(); - } - - /// - /// Create an instance of the TaskEntityDispatcher class for testing. - /// - /// Instance created for testing. - public TaskEntityDispatcher CreateTestEntityDispatcherInstance() - { - ILoggerFactory loggerFactory = null; - var entityManager = new NameVersionObjectManager(); - var entityMiddleware = new DispatchMiddlewarePipeline(); - var logger = new LogHelper(loggerFactory?.CreateLogger("DurableTask.Core")); - - return new TaskEntityDispatcher - ( - this.orchestrationService, - entityManager, - entityMiddleware, - logger, - ErrorPropagationMode.SerializeExceptions); - } - - /// - /// Method to test orchestration settings when entities schedule it. - /// - /// HistoryEvent contains the scheduled message. - public HistoryEvent TestScheduleOrchestrationTags() - { - return this.dispatcher.TestScheduleSendEvent(); - } - } -} diff --git a/src/DurableTask.Core/TaskEntityDispatcher.cs b/src/DurableTask.Core/TaskEntityDispatcher.cs index f04843566..a7ecb5267 100644 --- a/src/DurableTask.Core/TaskEntityDispatcher.cs +++ b/src/DurableTask.Core/TaskEntityDispatcher.cs @@ -182,7 +182,7 @@ async Task OnProcessWorkItemSessionAsync(TaskOrchestrationWorkItem workItem) } } - class WorkItemEffects + internal class WorkItemEffects { public List ActivityMessages; public List TimerMessages; @@ -794,7 +794,7 @@ void ProcessSendEventMessage(WorkItemEffects effects, OrchestrationInstance dest }); } - void ProcessSendStartMessage(WorkItemEffects effects, OrchestrationRuntimeState runtimeState, StartNewOrchestrationOperationAction action) + internal void ProcessSendStartMessage(WorkItemEffects effects, OrchestrationRuntimeState runtimeState, StartNewOrchestrationOperationAction action) { OrchestrationInstance destination = new OrchestrationInstance() { @@ -883,35 +883,5 @@ await this.dispatchPipeline.RunAsync(dispatchContext, async _ => return result; } - - /// - /// Test only. - /// - internal HistoryEvent TestScheduleSendEvent() - { - // Initialize arguments to pass to ProcessSendStartMessage(). - var effects = new WorkItemEffects(); - effects.taskIdCounter = 0; - effects.InstanceMessages = new List(); - - var mockEntityStartEvent = new ExecutionStartedEvent(-1, null) - { - OrchestrationInstance = new OrchestrationInstance(), - Name = "testentity", - Version = "1.0", - }; - var runtimeState = new OrchestrationRuntimeState(); - runtimeState.AddEvent(mockEntityStartEvent); - var action = new StartNewOrchestrationOperationAction() - { - InstanceId = "testsample", - Name = "test", - Version = "1.0", - Input = null, - }; - - this.ProcessSendStartMessage(effects, runtimeState,action); - return effects.InstanceMessages[0].Event; - } } } diff --git a/test/DurableTask.SqlServer.Tests/DurableTask.SqlServer.Tests.csproj b/test/DurableTask.SqlServer.Tests/DurableTask.SqlServer.Tests.csproj index cf578db09..e698b6266 100644 --- a/test/DurableTask.SqlServer.Tests/DurableTask.SqlServer.Tests.csproj +++ b/test/DurableTask.SqlServer.Tests/DurableTask.SqlServer.Tests.csproj @@ -23,7 +23,7 @@ - + From 4e4f13dced19e160d50651d3c1a176e021d0fee1 Mon Sep 17 00:00:00 2001 From: "naiyuantian@microsoft.com" Date: Tue, 7 May 2024 18:25:37 -0700 Subject: [PATCH 9/9] update test --- Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs b/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs index 42cc0b2c9..3e5032156 100644 --- a/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs +++ b/Test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs @@ -80,9 +80,9 @@ public void TestEntityDoesNotSetFireAndForgetTags() Assert.IsInstanceOfType(resultEvent, typeof(ExecutionStartedEvent)); var executionStartedEvent = (ExecutionStartedEvent)resultEvent; - // The resulting event should not contain a fire and forget tag + // The resulting event should contain a fire and forget tag bool hasFireAndForgetTag = executionStartedEvent.Tags.ContainsKey(OrchestrationTags.FireAndForget); - Assert.IsFalse(hasFireAndForgetTag); + Assert.IsTrue(hasFireAndForgetTag); } } }