forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGivenExponentialRetry.cs
More file actions
43 lines (37 loc) · 1.33 KB
/
GivenExponentialRetry.cs
File metadata and controls
43 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Tests
{
public class GivenExponentialRetry : SdkTest
{
public GivenExponentialRetry(ITestOutputHelper log) : base(log)
{
}
[Fact]
public async Task ItReturnsOnSuccess()
{
var retryCount = 0;
Func<Task<string>> action = () =>
{
retryCount++;
return Task.FromResult("done");
};
var res = await ExponentialRetry.ExecuteWithRetryOnFailure<string>(action);
retryCount.Should().Be(1);
}
[Fact]
public async Task ItRetriesOnError()
{
var retryCount = 0;
Func<Task<string?>> action = () => // Updated to use nullable reference type
{
retryCount++;
return Task.FromResult<string?>(null); // Updated to match nullable reference type
};
var res = await ExponentialRetry.ExecuteWithRetryOnFailure<string?>(action, 2, timer: () => ExponentialRetry.Timer(ExponentialRetry.TestingIntervals));
res.Should().BeNull();
retryCount.Should().Be(2);
}
}
}