Skip to content

Commit a9d7026

Browse files
authored
[Fixes #19666] [Components] Improve reliability of component quarantined tests (take 2) (#21499)
* Tries to increase the reliability of the tests by: * Trying to ensure that the server is up and running before connecting. * Retrying a connection attempt multiple times.
1 parent fdb0372 commit a9d7026

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/Components/Ignitor/src/BlazorClient.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,19 @@ public async Task<bool> ConnectAsync(Uri uri, bool connectAutomatically = true,
359359
HubConnection.On<string>("JS.Error", OnError);
360360
HubConnection.Closed += OnClosedAsync;
361361

362-
await HubConnection.StartAsync(CancellationToken);
362+
for (var i = 0; i < 10; i++)
363+
{
364+
try
365+
{
366+
await HubConnection.StartAsync(CancellationToken);
367+
break;
368+
}
369+
catch
370+
{
371+
await Task.Delay(500);
372+
// Retry 10 times
373+
}
374+
}
363375

364376
if (!connectAutomatically)
365377
{

src/Components/test/E2ETest/ServerExecutionTests/ComponentHubReliabilityTest.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Net;
6+
using System.Net.Http;
57
using System.Text.RegularExpressions;
68
using System.Threading.Tasks;
79
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
@@ -22,6 +24,32 @@ public ComponentHubReliabilityTest(BasicTestAppServerSiteFixture<ServerStartup>
2224
{
2325
}
2426

27+
protected override async Task InitializeAsync()
28+
{
29+
await base.InitializeAsync();
30+
31+
var rootUri = ServerFixture.RootUri;
32+
var baseUri = new Uri(rootUri, "/subdir");
33+
var client = new HttpClient();
34+
for (var i = 0; i < 10; i++)
35+
{
36+
try
37+
{
38+
var response = await client.GetAsync(baseUri + "/_negotiate");
39+
if (response.StatusCode == HttpStatusCode.OK)
40+
{
41+
break;
42+
}
43+
}
44+
catch
45+
{
46+
await Task.Delay(500);
47+
throw;
48+
}
49+
}
50+
51+
}
52+
2553
[Fact]
2654
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/19414")]
2755
public async Task CannotStartMultipleCircuits()

0 commit comments

Comments
 (0)