public async Task ScaleRecommendation_PendingOrchestrationStarts() { // Block the orchestration dispatch loop so that we can queue orchestrations without running them this.testService.OrchestrationServiceMock.Setup( svc => svc.LockNextTaskOrchestrationWorkItemAsync( It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>())) .Returns(() => Task.Delay(100).ContinueWith(t => default(TaskOrchestrationWorkItem))); // We can influence the recommended replica count by modifying concurrency settings this.testService.OrchestrationServiceOptions.MaxActiveOrchestrations = 1; await this.testService.StartWorkerAsync(); SqlOrchestrationService orchestrationService = this.testService.OrchestrationServiceMock.Object; // Initial scale recommendation should be zero int recommendation = await orchestrationService.GetRecommendedReplicaCountAsync(); Assert.Equal(0, recommendation); for (int i = 1; i <= 10; i++) { // Schedule an orchestration (it won't run, see above) await this.testService.RunOrchestration( null as string, $"EmptyOrchestration{i:00}", implementation : (ctx, input) => Task.FromResult(input)); // Scale recommendation increments with every new scheduled orchestration. // We pass in the previous recommendation to generate a log statement about the change. recommendation = await orchestrationService.GetRecommendedReplicaCountAsync(recommendation); Assert.Equal(i, recommendation); } // Validate the logs IReadOnlyList <LogEntry> recommendationChangeLogs = this.GetRecommendationChangeLogs(); Assert.Equal(10, recommendationChangeLogs.Count); for (int i = 0; i < recommendationChangeLogs.Count; i++) { LogEntry log = recommendationChangeLogs[i]; LogAssert.FieldEquals(log, "CurrentCount", i); LogAssert.FieldEquals(log, "RecommendedCount", i + 1); } }