From a9d702624a02ad4ebf593d9bf9c1c69f5702a6f5 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Wed, 6 May 2020 19:12:06 +0200 Subject: [PATCH] [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. --- src/Components/Ignitor/src/BlazorClient.cs | 14 +++++++++- .../ComponentHubReliabilityTest.cs | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Components/Ignitor/src/BlazorClient.cs b/src/Components/Ignitor/src/BlazorClient.cs index f690569228..5353659f36 100644 --- a/src/Components/Ignitor/src/BlazorClient.cs +++ b/src/Components/Ignitor/src/BlazorClient.cs @@ -359,7 +359,19 @@ namespace Ignitor HubConnection.On("JS.Error", OnError); HubConnection.Closed += OnClosedAsync; - await HubConnection.StartAsync(CancellationToken); + for (var i = 0; i < 10; i++) + { + try + { + await HubConnection.StartAsync(CancellationToken); + break; + } + catch + { + await Task.Delay(500); + // Retry 10 times + } + } if (!connectAutomatically) { diff --git a/src/Components/test/E2ETest/ServerExecutionTests/ComponentHubReliabilityTest.cs b/src/Components/test/E2ETest/ServerExecutionTests/ComponentHubReliabilityTest.cs index 616cdab1e0..e8cfaedea5 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/ComponentHubReliabilityTest.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/ComponentHubReliabilityTest.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Net; +using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; @@ -22,6 +24,32 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests { } + protected override async Task InitializeAsync() + { + await base.InitializeAsync(); + + var rootUri = ServerFixture.RootUri; + var baseUri = new Uri(rootUri, "/subdir"); + var client = new HttpClient(); + for (var i = 0; i < 10; i++) + { + try + { + var response = await client.GetAsync(baseUri + "/_negotiate"); + if (response.StatusCode == HttpStatusCode.OK) + { + break; + } + } + catch + { + await Task.Delay(500); + throw; + } + } + + } + [Fact] [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/19414")] public async Task CannotStartMultipleCircuits()