Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Fix a flaky test that depends on real system time #529

Merged
merged 1 commit into from
May 24, 2019
Merged

Conversation

joelverhagen
Copy link
Member

A test turned out to be flaky. Apparently Task.Delay can take less than the provided time to complete. I had assumed that the actual delay would always be greater than or equal to the provided TimeSpan, but apparently that is not true.

##[error]    NuGet.Services.AzureSearch.SearchService.AuxiliaryFileReloaderFacts+ReloadContinuouslyAsync.UsesReloadFrequencyOnSuccess [FAIL]

      Assert.InRange() Failure
      Range:  (00:00:00.1000000 - 01:00:00)
      Actual: 00:00:00.0975096
      Stack Trace:
        src\AzureSearchService\submodules\NuGet.Services.Metadata\tests\NuGet.Services.AzureSearch.Tests\SearchService\AuxiliaryFileReloaderFacts.cs(58,0): at NuGet.Services.AzureSearch.SearchService.AuxiliaryFileReloaderFacts.ReloadContinuouslyAsync.<UsesReloadFrequencyOnSuccess>d__3.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      Output:
        | NuGet.Services.AzureSearch.SearchService.AuxiliaryFileReloader Information: Trying to reload the auxiliary data.
        | NuGet.Services.AzureSearch.SearchService.AuxiliaryFileReloader Information: Waiting 00:00:00.1000000 before attempting to reload the auxiliary data again.
        | NuGet.Services.AzureSearch.SearchService.AuxiliaryFileReloader Information: Trying to reload the auxiliary data.

Failed build:
https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=2706000

Copy link
Contributor

@agr agr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure ISystemTime is a good name but can't come up with a better name :)

@joelverhagen
Copy link
Member Author

I'm not sure ISystemTime is a good name but can't come up with a better name :)

I drew inspiration from previous abstractions I've see around the DateTime/DateTimeOffset static methods. I figured we could add those here later when we need them and at that point it would be a generic wrapper around Time.

@joelverhagen joelverhagen merged commit 14f2318 into dev May 24, 2019
@joelverhagen joelverhagen deleted the jver-flaky branch May 24, 2019 23:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants