Test flakiness - Moving the first request into a retry block

Sometimes the first request to the application results in exceptions like 'No connection could be made because the target machine actively refused it'. Adding a retry to mitigate that.
This commit is contained in:
Praburaj 2014-11-19 13:35:55 -08:00
parent dbee8c1f6b
commit f72b23c871
1 changed files with 24 additions and 4 deletions

View File

@ -66,11 +66,31 @@ namespace E2ETests
httpClientHandler = new HttpClientHandler();
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);
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)
{
if (exception.InnerException is HttpRequestException)
{
Console.WriteLine("Failed to complete the request with error: {0}", exception.ToString());
Console.WriteLine("Retrying request..");
}
}
}
VerifyHomePage(response, responseContent);
//Verify the static file middleware can serve static content