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:
Praburaj 2014-06-02 12:17:57 -07:00
parent 6cd501c5f7
commit 516251a1c3
2 changed files with 64 additions and 27 deletions

View File

@ -43,7 +43,7 @@ namespace E2ETests
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));
@ -53,7 +53,7 @@ namespace E2ETests
}
else
{
throw new NotImplementedException("Self-Host variation not implemented");
return StartSelfHost(applicationPath, identityDbName);
}
}
@ -71,29 +71,67 @@ namespace E2ETests
var hostProcess = Process.Start(startInfo);
Console.WriteLine("Started iisexpress. Process Id : {0}", hostProcess.Id);
Thread.Sleep(2 * 1000);
return hostProcess;
}
//private static Process StartSelfHost(string applicationPath)
//{
// var klrPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".kre\packges", "KRE-svr50-x86.0.1-alpha-build-0450", @"bin\klr.exe");
// Console.WriteLine(klrPath);
private static Process StartSelfHost(string applicationPath, string identityDbName)
{
var startInfo = new ProcessStartInfo
{
FileName = "klr.exe",
Arguments = string.Format("--appbase {0} \"Microsoft.Framework.ApplicationHost\" web", applicationPath),
UseShellExecute = true,
CreateNoWindow = true
};
// var startInfo = new ProcessStartInfo
// {
// FileName = klrPath,
// Arguments = string.Format("--appbase {0} \"Microsoft.Framework.ApplicationHost\" web", applicationPath),
// UseShellExecute = true,
// CreateNoWindow = true
// };
var hostProcess = Process.Start(startInfo);
Console.WriteLine("Started klr.exe. Process Id : {0}", hostProcess.Id);
WaitTillDbCreated(identityDbName);
// var hostProcess = Process.Start(startInfo);
// Console.WriteLine("Started klr.exe. Process Id : {0}", hostProcess.Id);
// Thread.Sleep(10 * 1000);
return hostProcess;
}
// 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();
}
}
}
}

View File

@ -16,7 +16,7 @@ namespace E2ETests
[Theory]
[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)
{
var testStartTime = DateTime.Now;
@ -31,18 +31,19 @@ namespace E2ETests
Environment.SetEnvironmentVariable("SQLAZURECONNSTR_IdentityConnection", string.Format(Connection_string_Format, musicStoreIdentityDbName));
ApplicationBaseUrl = applicationBaseUrl;
var hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor);
var hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor, musicStoreIdentityDbName);
try
{
httpClientHandler = new HttpClientHandler();
httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) };
//Request to base address and check if various parts of the body are rendered
VerifyHomePage();
//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);
//Making a request to a protected resource should automatically redirect to login page
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);
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
Assert.Contains("ASP.NET MVC Music Store", responseContent, StringComparison.OrdinalIgnoreCase);