Skip to content

Commit efe9b95

Browse files
authored
Improve cdn test reliability (#6044)
1 parent 686ce02 commit efe9b95

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Identity/test/Identity.Test/CdnScriptTaghelperTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net.Http;
88
using System.Security.Cryptography;
99
using System.Text.RegularExpressions;
10+
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Xunit;
1213
using Xunit.Abstractions;
@@ -38,7 +39,7 @@ public async Task IdentityUI_ScriptTags_SubresourceIntegrityCheck()
3839
Assert.NotEmpty(scriptTags);
3940

4041
var shasum = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
41-
using (var client = new HttpClient())
42+
using (var client = new HttpClient(new RetryHandler(new HttpClientHandler() { })))
4243
{
4344
foreach (var script in scriptTags)
4445
{
@@ -62,6 +63,25 @@ public async Task IdentityUI_ScriptTags_SubresourceIntegrityCheck()
6263
});
6364
}
6465

66+
class RetryHandler : DelegatingHandler
67+
{
68+
public RetryHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }
69+
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
70+
{
71+
HttpResponseMessage result = null;
72+
for (var i = 0; i < 10; i++)
73+
{
74+
result = await base.SendAsync(request, cancellationToken);
75+
if (result.IsSuccessStatusCode)
76+
{
77+
return result;
78+
}
79+
await Task.Delay(1000);
80+
}
81+
return result;
82+
}
83+
}
84+
6585
private struct ScriptTag
6686
{
6787
public string Src;

0 commit comments

Comments
 (0)