Пример #1
0
        public async Task TaskReturnsVoid_OrchestratorFails()
        {
            using (TestOrchestrationHost host = TestHelpers.GetTestOrchestrationHost(false))
            {
                await host.StartAsync();

                TaskActivity activity = TestOrchestrationHost.MakeActivity <int, Task>(
                    delegate(TaskContext ctx, int input)
                {
                    return(null);
                });

                TestInstance <int> instance = await host.StartInlineOrchestration(
                    input : 123,
                    orchestrationName : "TestOrchestration",
                    implementation : (ctx, input) => ctx.ScheduleTask <int>("Activity", "", input),
                    activities : ("Activity", activity));

                // The expectedOutput value is the string that's passed into the InvalidOperationException
                await Task.WhenAll(instance.WaitForCompletion(
                                       expectedStatus: OrchestrationStatus.Completed,
                                       expectedOutput: 0));

                await host.StopAsync();
            }
        }
Пример #2
0
        public async Task RestartOrchestrationWithExternalEvents()
        {
            using TestOrchestrationHost host = TestHelpers.GetTestOrchestrationHost(enableExtendedSessions: false);
            await host.StartAsync();

            // This is the local method we'll use to continuously recreate the same instance.
            // It doesn't matter that the orchestration name is different as long as the instance ID is the same.
            Task <TestInstance <string> > CreateInstance(int i) => host.StartInlineOrchestration(
                input: "Hello, world!",
                instanceId: "Singleton",
                orchestrationName: $"EchoOrchestration{i}",
                implementation: (ctx, input) => Task.FromResult(input));

            // Start the first iteration and wait for it to complete.
            TestInstance <string> instance = await CreateInstance(0);

            await instance.WaitForCompletion();

            int restartIterations  = 10;
            int externalEventCount = 10;

            // We'll keep track of the execution IDs to make 100% sure we get new instances every iteration.
            var executionIds = new HashSet <string> {
                instance.ExecutionId
            };

            // Simultaneously send a bunch of external events as well as a "recreate" message. Repeat this
            // several times. Need to ensure that the orchestration can always be restarted reliably. It
            // doesn't matter whether the orchestration handles the external events or not.
            for (int i = 1; i <= restartIterations; i++)
            {
                List <Task> concurrentTasks = Enumerable.Range(0, externalEventCount).Select(j => instance.RaiseEventAsync("DummyEvent", j)).ToList();
                Task <TestInstance <string> > recreateInstanceTask = CreateInstance(i);
                concurrentTasks.Add(recreateInstanceTask);
                await Task.WhenAll(concurrentTasks);

                // Wait for the newly created instance to complete.
                instance = await recreateInstanceTask;
                await instance.WaitForCompletion();

                // Ensure that this is a new execution ID.
                Assert.IsTrue(executionIds.Add(instance.ExecutionId));
            }
        }