Add retry logic for Publishtests
This commit is contained in:
parent
715b744146
commit
2286b14290
|
|
@ -1,7 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace E2ETests
|
namespace E2ETests
|
||||||
|
|
@ -54,11 +56,34 @@ namespace E2ETests
|
||||||
httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true };
|
httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true };
|
||||||
httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) };
|
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.
|
//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;
|
//Add retry logic since tests are flaky on mono due to connection issues
|
||||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
for (int retryCount = 0; retryCount < 3; retryCount++)
|
||||||
var initializationCompleteTime = DateTime.Now;
|
{
|
||||||
Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds);
|
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);
|
VerifyHomePage(response, responseContent, true);
|
||||||
|
|
||||||
//Static files are served?
|
//Static files are served?
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -84,7 +85,7 @@ namespace E2ETests
|
||||||
}
|
}
|
||||||
catch (AggregateException exception)
|
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("Failed to complete the request with error: {0}", exception.ToString());
|
||||||
Console.WriteLine("Retrying request..");
|
Console.WriteLine("Retrying request..");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue