Adding a retry logic for NtlmAuth test
The other two tests already have this.
This commit is contained in:
parent
76017af97c
commit
56d6dfeb1b
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.Testing.xunit;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -47,12 +49,33 @@ 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);
|
||||
VerifyHomePage(response, responseContent, true);
|
||||
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 || 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);
|
||||
|
||||
//Check if the user name appears in the page
|
||||
Assert.Contains(string.Format("{0}\\{1}", Environment.UserDomainName, Environment.UserName), responseContent, StringComparison.OrdinalIgnoreCase);
|
||||
|
|
|
|||
Loading…
Reference in New Issue