Enabling self-host variation of the MusicStore tests
With this change the tests run on Helios+DesktopCLR and Self-Host+DesktopCLR.
This commit is contained in:
parent
6cd501c5f7
commit
516251a1c3
|
|
@ -43,7 +43,7 @@ namespace E2ETests
|
||||||
|
|
||||||
private const string APP_RELATIVE_PATH = @"..\..\src\MusicStore\";
|
private const string APP_RELATIVE_PATH = @"..\..\src\MusicStore\";
|
||||||
|
|
||||||
public static Process StartApplication(HostType hostType, KreFlavor kreFlavor)
|
public static Process StartApplication(HostType hostType, KreFlavor kreFlavor, string identityDbName)
|
||||||
{
|
{
|
||||||
string applicationPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, APP_RELATIVE_PATH));
|
string applicationPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, APP_RELATIVE_PATH));
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ namespace E2ETests
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("Self-Host variation not implemented");
|
return StartSelfHost(applicationPath, identityDbName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,29 +71,67 @@ namespace E2ETests
|
||||||
|
|
||||||
var hostProcess = Process.Start(startInfo);
|
var hostProcess = Process.Start(startInfo);
|
||||||
Console.WriteLine("Started iisexpress. Process Id : {0}", hostProcess.Id);
|
Console.WriteLine("Started iisexpress. Process Id : {0}", hostProcess.Id);
|
||||||
Thread.Sleep(2 * 1000);
|
|
||||||
|
|
||||||
return hostProcess;
|
return hostProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static Process StartSelfHost(string applicationPath)
|
private static Process StartSelfHost(string applicationPath, string identityDbName)
|
||||||
//{
|
{
|
||||||
// var klrPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".kre\packges", "KRE-svr50-x86.0.1-alpha-build-0450", @"bin\klr.exe");
|
var startInfo = new ProcessStartInfo
|
||||||
// Console.WriteLine(klrPath);
|
{
|
||||||
|
FileName = "klr.exe",
|
||||||
|
Arguments = string.Format("--appbase {0} \"Microsoft.Framework.ApplicationHost\" web", applicationPath),
|
||||||
|
UseShellExecute = true,
|
||||||
|
CreateNoWindow = true
|
||||||
|
};
|
||||||
|
|
||||||
// var startInfo = new ProcessStartInfo
|
var hostProcess = Process.Start(startInfo);
|
||||||
// {
|
Console.WriteLine("Started klr.exe. Process Id : {0}", hostProcess.Id);
|
||||||
// FileName = klrPath,
|
WaitTillDbCreated(identityDbName);
|
||||||
// Arguments = string.Format("--appbase {0} \"Microsoft.Framework.ApplicationHost\" web", applicationPath),
|
|
||||||
// UseShellExecute = true,
|
|
||||||
// CreateNoWindow = true
|
|
||||||
// };
|
|
||||||
|
|
||||||
// var hostProcess = Process.Start(startInfo);
|
return hostProcess;
|
||||||
// Console.WriteLine("Started klr.exe. Process Id : {0}", hostProcess.Id);
|
}
|
||||||
// Thread.Sleep(10 * 1000);
|
|
||||||
|
|
||||||
// return hostProcess;
|
//In case of self-host application activation happens immediately unlike iis where activation happens on first request.
|
||||||
//}
|
//So in self-host case, we need a way to block the first request until the application is initialized. In MusicStore application's case,
|
||||||
|
//identity DB creation is pretty much the last step of application setup. So waiting on this event will help us wait efficiently.
|
||||||
|
private static void WaitTillDbCreated(string identityDbName)
|
||||||
|
{
|
||||||
|
var identityDBFullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), identityDbName + ".mdf");
|
||||||
|
if (File.Exists(identityDBFullPath))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Database file '{0}' exists. Proceeding with the tests.", identityDBFullPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Watching for the DB file '{0}'", identityDBFullPath);
|
||||||
|
var dbWatch = new FileSystemWatcher(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), identityDbName + ".mdf");
|
||||||
|
dbWatch.EnableRaisingEvents = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!File.Exists(identityDBFullPath))
|
||||||
|
{
|
||||||
|
//Wait for a maximum of 1 minute assuming the slowest cold start.
|
||||||
|
var watchResult = dbWatch.WaitForChanged(WatcherChangeTypes.Created, 60 * 1000);
|
||||||
|
if (watchResult.ChangeType == WatcherChangeTypes.Created)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Database file created '{0}'. Proceeding with the tests.", identityDBFullPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Database file '{0}' not created", identityDBFullPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Received this exception while watching for Database file {0}", exception);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
dbWatch.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ namespace E2ETests
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(HostType.Helios, KreFlavor.DesktopClr, "http://localhost:5001/")]
|
[InlineData(HostType.Helios, KreFlavor.DesktopClr, "http://localhost:5001/")]
|
||||||
//[InlineData(HostType.SelfHost, KreFlavor.DesktopClr, "http://localhost:5002/")]
|
[InlineData(HostType.SelfHost, KreFlavor.DesktopClr, "http://localhost:5002/")]
|
||||||
public void SmokeTestSuite(HostType hostType, KreFlavor kreFlavor, string applicationBaseUrl)
|
public void SmokeTestSuite(HostType hostType, KreFlavor kreFlavor, string applicationBaseUrl)
|
||||||
{
|
{
|
||||||
var testStartTime = DateTime.Now;
|
var testStartTime = DateTime.Now;
|
||||||
|
|
@ -31,18 +31,19 @@ namespace E2ETests
|
||||||
Environment.SetEnvironmentVariable("SQLAZURECONNSTR_IdentityConnection", string.Format(Connection_string_Format, musicStoreIdentityDbName));
|
Environment.SetEnvironmentVariable("SQLAZURECONNSTR_IdentityConnection", string.Format(Connection_string_Format, musicStoreIdentityDbName));
|
||||||
|
|
||||||
ApplicationBaseUrl = applicationBaseUrl;
|
ApplicationBaseUrl = applicationBaseUrl;
|
||||||
var hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor);
|
var hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor, musicStoreIdentityDbName);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClientHandler = new HttpClientHandler();
|
httpClientHandler = new HttpClientHandler();
|
||||||
httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) };
|
httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) };
|
||||||
|
|
||||||
//Request to base address and check if various parts of the body are rendered
|
//Request to base address and check if various parts of the body are rendered & measure the cold startup time.
|
||||||
VerifyHomePage();
|
var response = httpClient.GetAsync(string.Empty).Result;
|
||||||
|
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||||
var initializationCompleteTime = DateTime.Now;
|
var initializationCompleteTime = DateTime.Now;
|
||||||
Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds);
|
Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds);
|
||||||
|
VerifyHomePage(response, responseContent);
|
||||||
|
|
||||||
//Making a request to a protected resource should automatically redirect to login page
|
//Making a request to a protected resource should automatically redirect to login page
|
||||||
AccessStoreWithoutPermissions();
|
AccessStoreWithoutPermissions();
|
||||||
|
|
@ -109,10 +110,8 @@ namespace E2ETests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyHomePage()
|
private void VerifyHomePage(HttpResponseMessage response, string responseContent)
|
||||||
{
|
{
|
||||||
var response = httpClient.GetAsync(string.Empty).Result;
|
|
||||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
|
||||||
Console.WriteLine("Home page content : {0}", responseContent);
|
Console.WriteLine("Home page content : {0}", responseContent);
|
||||||
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue