Skip to content

Commit ca1f8c4

Browse files
surayya-MSbaronfel
authored andcommitted
set retry to 0 in test
1 parent 322f3ca commit ca1f8c4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal sealed class Registry
7575
private const string DockerHubRegistry2 = "registry.hub.docker.com";
7676
private static readonly int s_defaultChunkSizeBytes = 1024 * 64;
7777
private const int MaxDownloadRetries = 5;
78-
private const int FixedDownloadDelayInSeconds = 1;
78+
private readonly Func<TimeSpan> _retryDelayProvider;
7979

8080
private readonly ILogger _logger;
8181
private readonly IRegistryAPI _registryAPI;
@@ -88,7 +88,7 @@ internal sealed class Registry
8888
/// </summary>
8989
public string RegistryName { get; }
9090

91-
internal Registry(string registryName, ILogger logger, IRegistryAPI registryAPI, RegistrySettings? settings = null) :
91+
internal Registry(string registryName, ILogger logger, IRegistryAPI registryAPI, RegistrySettings? settings = null, Func<TimeSpan>? retryDelayProvider = null) :
9292
this(new Uri($"https://{registryName}"), logger, registryAPI, settings)
9393
{ }
9494

@@ -97,15 +97,15 @@ internal Registry(string registryName, ILogger logger, RegistryMode mode, Regist
9797
{ }
9898

9999

100-
internal Registry(Uri baseUri, ILogger logger, IRegistryAPI registryAPI, RegistrySettings? settings = null) :
100+
internal Registry(Uri baseUri, ILogger logger, IRegistryAPI registryAPI, RegistrySettings? settings = null, Func<TimeSpan>? retryDelayProvider = null) :
101101
this(baseUri, logger, new RegistryApiFactory(registryAPI), settings)
102102
{ }
103103

104104
internal Registry(Uri baseUri, ILogger logger, RegistryMode mode, RegistrySettings? settings = null) :
105105
this(baseUri, logger, new RegistryApiFactory(mode), settings)
106106
{ }
107107

108-
private Registry(Uri baseUri, ILogger logger, RegistryApiFactory factory, RegistrySettings? settings = null)
108+
private Registry(Uri baseUri, ILogger logger, RegistryApiFactory factory, RegistrySettings? settings = null, Func<TimeSpan>? retryDelayProvider = null)
109109
{
110110
RegistryName = DeriveRegistryName(baseUri);
111111

@@ -119,6 +119,8 @@ private Registry(Uri baseUri, ILogger logger, RegistryApiFactory factory, Regist
119119
_logger = logger;
120120
_settings = settings ?? new RegistrySettings(RegistryName);
121121
_registryAPI = factory.Create(RegistryName, BaseUri, logger, _settings.IsInsecure);
122+
123+
_retryDelayProvider = retryDelayProvider ?? (() => TimeSpan.FromSeconds(1));
122124
}
123125

124126
private static string DeriveRegistryName(Uri baseUri)
@@ -439,7 +441,7 @@ public async Task<string> DownloadBlobAsync(string repository, Descriptor descri
439441
_logger.LogTrace("Download attempt {0}/{1} for repository '{2}' failed. Error: {3}", retryCount, MaxDownloadRetries, repository, ex.ToString());
440442

441443
// Wait before retrying
442-
await Task.Delay(TimeSpan.FromSeconds(FixedDownloadDelayInSeconds), cancellationToken).ConfigureAwait(false);
444+
await Task.Delay(_retryDelayProvider(), cancellationToken).ConfigureAwait(false);
443445
}
444446
}
445447

src/Tests/Microsoft.NET.Build.Containers.UnitTests/RegistryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public async Task DownloadBlobAsync_RetriesOnFailure()
556556
.ThrowsAsync(new Exception("Simulated failure 2")) // Second attempt fails
557557
.ReturnsAsync(new MemoryStream(new byte[] { 1, 2, 3 })); // Third attempt succeeds
558558

559-
Registry registry = new(repoName, logger, mockRegistryAPI.Object);
559+
Registry registry = new(repoName, logger, mockRegistryAPI.Object, null, () => TimeSpan.Zero);
560560

561561
// Act
562562
var result = await registry.DownloadBlobAsync(repoName, descriptor, cancellationToken);

0 commit comments

Comments
 (0)