diff --git a/test/E2ETests/PublishAndRunTests.cs b/test/E2ETests/PublishAndRunTests.cs index 3e2086f92f..af32b9f096 100644 --- a/test/E2ETests/PublishAndRunTests.cs +++ b/test/E2ETests/PublishAndRunTests.cs @@ -1,7 +1,9 @@ using System; using System.Diagnostics; using System.IO; +using System.Net; using System.Net.Http; +using System.Threading; using Xunit; namespace E2ETests @@ -54,11 +56,34 @@ namespace E2ETests httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true }; httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) }; + HttpResponseMessage response = null; + string responseContent = null; + var initializationCompleteTime = DateTime.MinValue; + //Request to base address and check if various parts of the body are rendered & measure the cold startup time. - var response = httpClient.GetAsync(string.Empty).Result; - var responseContent = response.Content.ReadAsStringAsync().Result; - var initializationCompleteTime = DateTime.Now; - Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds); + //Add retry logic since tests are flaky on mono due to connection issues + for (int retryCount = 0; retryCount < 3; retryCount++) + { + try + { + response = httpClient.GetAsync(string.Empty).Result; + responseContent = response.Content.ReadAsStringAsync().Result; + initializationCompleteTime = DateTime.Now; + Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds); + break; //Went through successfully + } + catch (AggregateException exception) + { + // Both type exceptions thrown by Mono which are resolved by retry logic + if (exception.InnerException is HttpRequestException || exception.InnerException is WebException) + { + Console.WriteLine("Failed to complete the request with error: {0}", exception.ToString()); + Console.WriteLine("Retrying request.."); + Thread.Sleep(1 * 1000); //Wait for a second before retry + } + } + } + VerifyHomePage(response, responseContent, true); //Static files are served? diff --git a/test/E2ETests/SmokeTests.cs b/test/E2ETests/SmokeTests.cs index f836dd37f7..933f10c66f 100644 --- a/test/E2ETests/SmokeTests.cs +++ b/test/E2ETests/SmokeTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Net; using System.Net.Http; using System.Threading; using Xunit; @@ -84,7 +85,7 @@ namespace E2ETests } catch (AggregateException exception) { - if (exception.InnerException is HttpRequestException) + if (exception.InnerException is HttpRequestException || exception.InnerException is WebException) { Console.WriteLine("Failed to complete the request with error: {0}", exception.ToString()); Console.WriteLine("Retrying request..");