Skip to content

Commit

Permalink
Fix flaky test CanRetryOnConflict (#10104)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen authored Aug 2, 2024
1 parent 1d62552 commit d25d34d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/NuGet.Services.AzureSearch.Tests/IndexBuilderFacts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -50,7 +50,10 @@ public async Task CanRetryOnConflict()
sw.Stop();

_cloudBlobContainer.Verify(x => x.CreateAsync(true), Times.Exactly(2));
Assert.InRange(sw.Elapsed, _retryDuration, TimeSpan.MaxValue);

// allow for some variance in the retry duration
// 15ms due to Windows clock: https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.delay
Assert.InRange(sw.Elapsed, _retryDuration - TimeSpan.FromMilliseconds(16), TimeSpan.MaxValue);
}

[Fact]
Expand Down Expand Up @@ -140,7 +143,7 @@ public BaseFacts(ITestOutputHelper output)
StorageContainer = "container-name",
};
_logger = output.GetLogger<BlobContainerBuilder>();
_retryDuration = TimeSpan.FromMilliseconds(10);
_retryDuration = TimeSpan.FromMilliseconds(100);

_options
.Setup(x => x.Value)
Expand All @@ -160,7 +163,7 @@ protected void EnableConflict()
{
_cloudBlobContainer
.SetupSequence(x => x.CreateAsync(It.IsAny<bool>()))
.Throws(new CloudBlobConflictException(null))
.ThrowsAsync(new CloudBlobConflictException(null))
.Returns(Task.CompletedTask);
}

Expand Down

0 comments on commit d25d34d

Please sign in to comment.