diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Watchdogs/Watchdog.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Watchdogs/Watchdog.cs index 19de170bff..899d8dd38a 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 @@ internal abstract class Watchdog 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 @@ public async Task ExecuteAsync(CancellationToken cancellationToken) { _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 @@ private async Task OnNextTickAsync(CancellationToken cancellationToken) } } - 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 c18bddf418..3d3134428f 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 @@ FOR INSERT 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 @@ public async Task AdvanceVisibility() 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); }