-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathVersionServiceRetryTests.cs
More file actions
77 lines (66 loc) · 2.27 KB
/
Copy pathVersionServiceRetryTests.cs
File metadata and controls
77 lines (66 loc) · 2.27 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using GeneralUpdate.Core.Network;
namespace CoreTest.Network;
public class VersionServiceRetryTests
{
[Fact]
public void IsRetryable_OperationCanceledException_ReturnsFalse()
{
Assert.False(IsRetryable(new OperationCanceledException("cancel")));
}
[Fact]
public void IsRetryable_TaskCanceledException_ReturnsFalse()
{
// TaskCanceledException inherits from OperationCanceledException,
// which is checked first → not retryable
Assert.False(IsRetryable(new TaskCanceledException("timeout")));
}
[Fact]
public void IsRetryable_TimeoutException_ReturnsTrue()
{
Assert.True(IsRetryable(new TimeoutException("timeout")));
}
[Fact]
public void IsRetryable_IOException_ReturnsTrue()
{
Assert.True(IsRetryable(new IOException("network down")));
}
[Fact]
public void IsRetryable_HttpRequestExceptionWithoutTimeout_ReturnsFalse()
{
Assert.False(IsRetryable(new HttpRequestException("Forbidden 403")));
Assert.False(IsRetryable(new HttpRequestException("Not Found 404")));
Assert.False(IsRetryable(new HttpRequestException("Connection refused")));
}
[Fact]
public void IsRetryable_InvalidOperationException_ReturnsFalse()
{
Assert.False(IsRetryable(new InvalidOperationException("boom")));
}
[Fact]
public void IsRetryable_NullReferenceException_ReturnsFalse()
{
Assert.False(IsRetryable(new NullReferenceException()));
}
[Fact]
public void HttpClientProvider_Shared_ReturnsSameInstance()
{
var client1 = HttpClientProvider.Shared;
var client2 = HttpClientProvider.Shared;
Assert.Same(client1, client2);
}
[Fact]
public void HttpClientProvider_Shared_IsNotNull()
{
Assert.NotNull(HttpClientProvider.Shared);
}
// Matches actual VersionService.IsRetryable logic
private static bool IsRetryable(Exception ex)
{
if (ex is OperationCanceledException) return false;
if (ex is TaskCanceledException or TimeoutException or IOException) return true;
if (ex is HttpRequestException h &&
(h.Message ?? "").Contains("timeout", StringComparison.OrdinalIgnoreCase))
return true;
return false;
}
}