public void WaitAny_WaitsForStop_WhenAllTasksAreNotCompleted(bool completed, bool expectedWaitForStop) { var history = DurableTestUtilities.MergeHistories( CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true), CreateActivityHistory("FunctionA", scheduled: true, completed: false, output: "\"Result1\""), CreateActivityHistory("FunctionA", scheduled: true, completed: completed, output: "\"Result2\"") ); var durableTaskHandler = new DurableTaskHandler(); var orchestrationContext = new OrchestrationContext { History = history }; var tasksToWaitFor = new ReadOnlyCollection <DurableTask>( new DurableTask[] { new ActivityInvocationTask("FunctionA", FunctionInput), new ActivityInvocationTask("FunctionA", FunctionInput) }); DurableTestUtilities.VerifyWaitForDurableTasks( durableTaskHandler, _delayBeforeStopping, expectedWaitForStop, () => { durableTaskHandler.WaitAny(tasksToWaitFor, orchestrationContext, _ => { }); }); }
protected override void EndProcessing() { var privateData = (Hashtable)MyInvocation.MyCommand.Module.PrivateData; var context = (OrchestrationContext)privateData[SetFunctionInvocationContextCommand.ContextKey]; if (Any.IsPresent) { _durableTaskHandler.WaitAny(Task, context, WriteObject); } else { _durableTaskHandler.WaitAll(Task, context, WriteObject); } }
public void WaitAll_And_WaitAny_StartNewActivityBatch(bool invokeWaitAll, bool invokeWaitAny, int expectedNumberOfBatches) { var orchestrationContext = new OrchestrationContext { History = new HistoryEvent[0] }; var durableTaskHandler = new DurableTaskHandler(); durableTaskHandler.StopAndInitiateDurableTaskOrReplay( new ActivityInvocationTask("Function", "Input"), orchestrationContext, noWait: true, output: _ => {}, onFailure: _ => {} ); if (invokeWaitAll) { durableTaskHandler.Stop(); // just to avoid the next call getting stuck waiting for a stop event durableTaskHandler.WaitAll(new DurableTask[0], orchestrationContext, output: _ => {}); } if (invokeWaitAny) { durableTaskHandler.Stop(); // just to avoid the next call getting stuck waiting for a stop event durableTaskHandler.WaitAny(new DurableTask[0], orchestrationContext, output: _ => {}); } durableTaskHandler.StopAndInitiateDurableTaskOrReplay( new ActivityInvocationTask("Function", "Input"), orchestrationContext, noWait: true, output: _ => {}, onFailure: _ => {} ); var(_, actions) = orchestrationContext.OrchestrationActionCollector.WaitForActions(new AutoResetEvent(initialState: true)); Assert.Equal(expectedNumberOfBatches, actions.Count); }
public void WaitAny_OutputsEarliestCompletedTask_WhenAnyTaskCompleted(bool completed) { var history = DurableTestUtilities.MergeHistories( CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true), CreateActivityHistory("FunctionA", scheduled: true, restartTime: _restartTime, completed: completed, output: "\"Result1\"", orchestratorStartedIsProcessed: false), CreateActivityHistory("FunctionA", scheduled: false, completed: false, output: "\"Result2\""), CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false) ); var orchestrationContext = new OrchestrationContext { History = history }; var firedTimer = new DurableTimerTask(_fireAt); var completedActivity = new ActivityInvocationTask("FunctionA", FunctionInput); var tasksToWaitFor = new ReadOnlyCollection <DurableTask>( new DurableTask[] { completedActivity, new ActivityInvocationTask("FunctionA", FunctionInput), firedTimer }); var allOutput = new List <object>(); var durableTaskHandler = new DurableTaskHandler(); durableTaskHandler.WaitAny(tasksToWaitFor, orchestrationContext, output => { allOutput.Add(output); }); if (completed) { Assert.Equal(new[] { completedActivity }, allOutput); } else { Assert.Equal(new[] { firedTimer }, allOutput); } VerifyNoOrchestrationActionAdded(orchestrationContext); }
public void CurrentUtcDateTime_UpdatesToNextOrchestratorStartedTimestamp_IfAnyActivitiesCompleted_WhenWaitAnyIsCalled(bool anyCompleted) { var activityFunctions = new Dictionary <string, bool>(); activityFunctions.Add("FunctionA", false); activityFunctions.Add("FunctionB", anyCompleted); activityFunctions.Add("FunctionC", false); var history = DurableTestUtilities.MergeHistories( CreateOrchestratorStartedHistory(startTime: _startTime, isProcessed: true), CreateNoWaitActivityHistory(scheduled: activityFunctions, restartTime: _restartTime, orchestratorStartedIsProcessed: false), CreateOrchestratorStartedHistory(startTime: _shouldNotHitTime, isProcessed: false) ); OrchestrationContext context = new OrchestrationContext { History = history, CurrentUtcDateTime = _startTime }; var tasksToWaitFor = new ReadOnlyCollection <ActivityInvocationTask>( new[] { "FunctionA", "FunctionB", "FunctionC" }.Select(name => new ActivityInvocationTask(name, FunctionInput)).ToArray()); var durableTaskHandler = new DurableTaskHandler(); var allOutput = new List <object>(); if (!anyCompleted) { DurableTestUtilities.EmulateStop(durableTaskHandler); } durableTaskHandler.WaitAny(tasksToWaitFor, context, output => allOutput.Add(output)); if (anyCompleted) { Assert.Equal(_restartTime, context.CurrentUtcDateTime); } else { Assert.Equal(_startTime, context.CurrentUtcDateTime); } }