From 963c76f7707470fd8d58a88d023b35c8503ada89 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Tue, 26 Aug 2014 16:48:39 -0700 Subject: [PATCH] Updating deployment helpers to start the host on mono. --- test/E2ETests/DeploymentUtility.cs | 62 ++++++++++++++++++++++++------ test/E2ETests/SmokeTests.cs | 7 +--- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/test/E2ETests/DeploymentUtility.cs b/test/E2ETests/DeploymentUtility.cs index cf92def9ff..79c37ef1bc 100644 --- a/test/E2ETests/DeploymentUtility.cs +++ b/test/E2ETests/DeploymentUtility.cs @@ -1,12 +1,13 @@ using System; +using System.ComponentModel; using System.Diagnostics; using System.IO; -using System.Threading; +using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; -using System.ComponentModel; namespace E2ETests { @@ -56,26 +57,31 @@ namespace E2ETests public static Process StartApplication(ServerType hostType, KreFlavor kreFlavor, KreArchitecture kreArchitecture, string identityDbName) { - if (kreFlavor == KreFlavor.Mono) - { - throw new NotImplementedException("Not implemented for Mono"); - } - string applicationPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, APP_RELATIVE_PATH)); - //Tweak the %PATH% to the point to the right KREFLAVOR - Environment.SetEnvironmentVariable("PATH", SwitchPathToKreFlavor(kreFlavor, kreArchitecture)); + var backupKreDefaultLibPath = Environment.GetEnvironmentVariable("KRE_DEFAULT_LIB"); //To avoid the KRE_DEFAULT_LIB of the test process flowing into Helios, set it to empty Environment.SetEnvironmentVariable("KRE_DEFAULT_LIB", string.Empty); + Process hostProcess = null; - if (hostType == ServerType.Helios) + if (kreFlavor == KreFlavor.Mono) { - hostProcess = StartHeliosHost(applicationPath, kreArchitecture); + hostProcess = StartMonoHost(hostType, applicationPath); } else { - hostProcess = StartSelfHost(hostType, applicationPath, identityDbName); + //Tweak the %PATH% to the point to the right KREFLAVOR + Environment.SetEnvironmentVariable("PATH", SwitchPathToKreFlavor(kreFlavor, kreArchitecture)); + + if (hostType == ServerType.Helios) + { + hostProcess = StartHeliosHost(applicationPath, kreArchitecture); + } + else + { + hostProcess = StartSelfHost(hostType, applicationPath, identityDbName); + } } //Restore the KRE_DEFAULT_LIB after starting the host process @@ -83,6 +89,38 @@ namespace E2ETests return hostProcess; } + private static Process StartMonoHost(ServerType hostType, string applicationPath) + { + var path = Environment.GetEnvironmentVariable("PATH"); + var kreBin = path.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Where(c => c.Contains("KRE-mono45")).FirstOrDefault(); + + if (string.IsNullOrWhiteSpace(kreBin)) + { + throw new Exception("KRE not detected on the machine."); + } + + var monoPath = Path.Combine(kreBin, "mono"); + var klrMonoManaged = Path.Combine(kreBin, "klr.mono.managed.dll"); + var applicationHost = Path.Combine(kreBin, "Microsoft.Framework.ApplicationHost"); + + Console.WriteLine(string.Format("Executing command: {0} {1} --appbase {2} {3} {4}", monoPath, klrMonoManaged, applicationPath, applicationHost, hostType.ToString())); + + //https://github.com/aspnet/KRuntime/issues/580 + var startInfo = new ProcessStartInfo + { + FileName = monoPath, + Arguments = string.Format("{0} --appbase {1} {2} {3}", klrMonoManaged, applicationPath, applicationHost, hostType.ToString()), + UseShellExecute = true, + CreateNoWindow = true + }; + + var hostProcess = Process.Start(startInfo); + Console.WriteLine("Started {0}. Process Id : {1}", hostProcess.MainModule.FileName, hostProcess.Id); + Thread.Sleep(5 * 1000); + + return hostProcess; + } + private static Process StartHeliosHost(string applicationPath, KreArchitecture kreArchitecture) { CopyAspNetLoader(applicationPath); diff --git a/test/E2ETests/SmokeTests.cs b/test/E2ETests/SmokeTests.cs index 7fffc965a7..80e8c4c484 100644 --- a/test/E2ETests/SmokeTests.cs +++ b/test/E2ETests/SmokeTests.cs @@ -77,11 +77,8 @@ namespace E2ETests try { - if (!RunningOnMono) - { - //Deployment helpers not setup for mono yet. Until then set the ApplicationBaseUrl to some static url. - hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor, architecture, musicStoreDbName); - } + //Deployment helpers not setup for mono yet. Until then set the ApplicationBaseUrl to some static url. + hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor, architecture, musicStoreDbName); httpClientHandler = new HttpClientHandler(); httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) };