From 830934f72ce15d25ff12fd7371631ca7480c58a8 Mon Sep 17 00:00:00 2001 From: Chris Gillum Date: Thu, 10 Oct 2024 10:26:46 -0700 Subject: [PATCH] PR feedback and minor cleanup --- .../SqlMetricsProvider.cs | 2 +- .../SqlTargetScaler.cs | 3 ++- .../TargetBasedScalingTests.cs | 13 +++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/DurableTask.SqlServer.AzureFunctions/SqlMetricsProvider.cs b/src/DurableTask.SqlServer.AzureFunctions/SqlMetricsProvider.cs index 9dd5680..8c17b88 100644 --- a/src/DurableTask.SqlServer.AzureFunctions/SqlMetricsProvider.cs +++ b/src/DurableTask.SqlServer.AzureFunctions/SqlMetricsProvider.cs @@ -10,7 +10,7 @@ public class SqlMetricsProvider { readonly SqlOrchestrationService service; - public SqlMetricsProvider(SqlOrchestrationService service, int? previousWorkerCount = null) + public SqlMetricsProvider(SqlOrchestrationService service) { this.service = service; } diff --git a/src/DurableTask.SqlServer.AzureFunctions/SqlTargetScaler.cs b/src/DurableTask.SqlServer.AzureFunctions/SqlTargetScaler.cs index b98169c..116efae 100644 --- a/src/DurableTask.SqlServer.AzureFunctions/SqlTargetScaler.cs +++ b/src/DurableTask.SqlServer.AzureFunctions/SqlTargetScaler.cs @@ -4,6 +4,7 @@ #if FUNCTIONS_V4 namespace DurableTask.SqlServer.AzureFunctions { + using System; using System.Threading.Tasks; using Microsoft.Azure.WebJobs.Host.Scale; @@ -28,7 +29,7 @@ public async Task GetScaleResultAsync(TargetScalerContext co SqlScaleMetric sqlScaleMetric = await this.sqlMetricsProvider.GetMetricsAsync(); return new TargetScalerResult { - TargetWorkerCount = sqlScaleMetric.RecommendedReplicaCount, + TargetWorkerCount = Math.Max(0, sqlScaleMetric.RecommendedReplicaCount), }; } } diff --git a/test/DurableTask.SqlServer.AzureFunctions.Tests/TargetBasedScalingTests.cs b/test/DurableTask.SqlServer.AzureFunctions.Tests/TargetBasedScalingTests.cs index d4a7fb5..9c6a793 100644 --- a/test/DurableTask.SqlServer.AzureFunctions.Tests/TargetBasedScalingTests.cs +++ b/test/DurableTask.SqlServer.AzureFunctions.Tests/TargetBasedScalingTests.cs @@ -3,14 +3,11 @@ namespace DurableTask.SqlServer.AzureFunctions.Tests { - using System; using DurableTask.Core; using Microsoft.Azure.WebJobs.Extensions.DurableTask; using Microsoft.Azure.WebJobs.Host.Scale; - using Microsoft.Extensions.Logging; using Moq; using Xunit; - using Xunit.Abstractions; public class TargetBasedScalingTests { @@ -21,10 +18,10 @@ public TargetBasedScalingTests() { this.orchestrationServiceMock = new Mock(MockBehavior.Strict); + SqlOrchestrationService? nullServiceArg = null; // not needed for this test this.metricsProviderMock = new Mock( - MockBehavior.Strict, - null, - null); + behavior: MockBehavior.Strict, + nullServiceArg); } [Theory] @@ -40,14 +37,14 @@ public async void TargetBasedScalingTest(int expectedTargetWorkerCount) new Mock().Object, "connectionName"); - SqlScaleMetric sqlScaleMetric = new SqlScaleMetric() + var sqlScaleMetric = new SqlScaleMetric() { RecommendedReplicaCount = expectedTargetWorkerCount, }; this.metricsProviderMock.Setup(m => m.GetMetricsAsync(null)).ReturnsAsync(sqlScaleMetric); - SqlTargetScaler targetScaler = new SqlTargetScaler( + var targetScaler = new SqlTargetScaler( "functionId", this.metricsProviderMock.Object);