From e9a016285f723ddb5e84c442cfcfcccdb70f3fac Mon Sep 17 00:00:00 2001 From: Brendan Kowitz Date: Wed, 9 Oct 2024 11:02:29 -0700 Subject: [PATCH] Fixes missed _periodSec variable (#4666) --- .../Features/Watchdogs/Watchdog.cs | 18 ++++++++---------- .../Persistence/SqlServerWatchdogTests.cs | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Watchdogs/Watchdog.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Watchdogs/Watchdog.cs index 19de170bf..899d8dd38 100644 --- a/src/Microsoft.Health.Fhir.SqlServer/Features/Watchdogs/Watchdog.cs +++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Watchdogs/Watchdog.cs @@ -21,8 +21,6 @@ namespace Microsoft.Health.Fhir.SqlServer.Features.Watchdogs private readonly ISqlRetryService _sqlRetryService; private readonly ILogger _logger; private readonly WatchdogLease _watchdogLease; - private double _periodSec; - private double _leasePeriodSec; private readonly FhirTimer _fhirTimer; protected Watchdog(ISqlRetryService sqlRetryService, ILogger logger) @@ -60,11 +58,11 @@ namespace Microsoft.Health.Fhir.SqlServer.Features.Watchdogs { _logger.LogInformation($"{Name}.ExecuteAsync: starting..."); - await InitParamsAsync(PeriodSec, LeasePeriodSec); + await InitParamsAsync(); await Task.WhenAll( - _fhirTimer.ExecuteAsync(_periodSec, OnNextTickAsync, cancellationToken), - _watchdogLease.ExecuteAsync(AllowRebalance, _leasePeriodSec, cancellationToken)); + _fhirTimer.ExecuteAsync(PeriodSec, OnNextTickAsync, cancellationToken), + _watchdogLease.ExecuteAsync(AllowRebalance, LeasePeriodSec, cancellationToken)); _logger.LogInformation($"{Name}.ExecuteAsync: completed."); } @@ -85,7 +83,7 @@ namespace Microsoft.Health.Fhir.SqlServer.Features.Watchdogs } } - private async Task InitParamsAsync(double periodSec, double leasePeriodSec) // No CancellationToken is passed since we shouldn't cancel initialization. + private async Task InitParamsAsync() // No CancellationToken is passed since we shouldn't cancel initialization. { using (_logger.BeginTimedScope($"{Name}.InitParamsAsync")) { @@ -98,13 +96,13 @@ INSERT INTO dbo.Parameters (Id,Number) SELECT @PeriodSecId, @PeriodSec INSERT INTO dbo.Parameters (Id,Number) SELECT @LeasePeriodSecId, @LeasePeriodSec "); cmd.Parameters.AddWithValue("@PeriodSecId", PeriodSecId); - cmd.Parameters.AddWithValue("@PeriodSec", periodSec); + cmd.Parameters.AddWithValue("@PeriodSec", PeriodSec); cmd.Parameters.AddWithValue("@LeasePeriodSecId", LeasePeriodSecId); - cmd.Parameters.AddWithValue("@LeasePeriodSec", leasePeriodSec); + cmd.Parameters.AddWithValue("@LeasePeriodSec", LeasePeriodSec); await cmd.ExecuteNonQueryAsync(_sqlRetryService, _logger, CancellationToken.None); - _periodSec = await GetPeriodAsync(CancellationToken.None); - _leasePeriodSec = await GetLeasePeriodAsync(CancellationToken.None); + PeriodSec = await GetPeriodAsync(CancellationToken.None); + LeasePeriodSec = await GetLeasePeriodAsync(CancellationToken.None); await InitAdditionalParamsAsync(); diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlServerWatchdogTests.cs b/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlServerWatchdogTests.cs index c18bddf41..3d3134428 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlServerWatchdogTests.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/SqlServerWatchdogTests.cs @@ -214,7 +214,7 @@ END Task wdTask = wd.ExecuteAsync(cts.Token); DateTime startTime = DateTime.UtcNow; - while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 10) + while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 20) { await Task.Delay(TimeSpan.FromSeconds(0.2), cts.Token); } @@ -251,7 +251,7 @@ END Task wdTask = wd.ExecuteAsync(cts.Token); var startTime = DateTime.UtcNow; - while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 10) + while (!wd.IsLeaseHolder && (DateTime.UtcNow - startTime).TotalSeconds < 20) { await Task.Delay(TimeSpan.FromSeconds(0.2), cts.Token); }