From 7a4a945fd65e442265c44150800b5f2e3e8349c8 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Mon, 30 Jul 2018 12:58:48 -0700 Subject: [PATCH] Stop site and app pool before restoring config (#1112) --- .../IISApplication.cs | 46 +++++++++++++++---- .../IISDeployer.cs | 6 ++- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISApplication.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISApplication.cs index bf0c338efc..ce1f3e426e 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISApplication.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISApplication.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting } AddTemporaryAppHostConfig(); - var apppool = ConfigureAppPool(contentRoot); + ConfigureAppPool(contentRoot); ConfigureSite(contentRoot, port); @@ -73,11 +73,11 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting _serverManager.CommitChanges(); - await WaitUntilSiteStarted(apppool); + await WaitUntilSiteStarted(); } } - private async Task WaitUntilSiteStarted(ApplicationPool appPool) + private async Task WaitUntilSiteStarted() { var sw = Stopwatch.StartNew(); @@ -85,12 +85,19 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting { try { - var site = _serverManager.Sites.FirstOrDefault(s => s.Name.Equals(WebSiteName)); + var serverManager = new ServerManager(); + var appPool = serverManager.ApplicationPools.FirstOrDefault(s => s.Name.Equals(AppPoolName)); + var site = serverManager.Sites.FirstOrDefault(s => s.Name.Equals(WebSiteName)); if (site.State == ObjectState.Started) { - _logger.LogInformation($"Site {WebSiteName} has started."); - return; + var workerProcess = appPool.WorkerProcesses.SingleOrDefault(); + if (workerProcess != null) + { + HostProcess = Process.GetProcessById(workerProcess.ProcessId); + _logger.LogInformation($"Site {WebSiteName} has started."); + return; + } } else if (site.State != ObjectState.Starting) { @@ -122,11 +129,15 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting return; } - RestoreAppHostConfig(); + StopSite(); + + StopAppPool(); _serverManager.CommitChanges(); await WaitUntilSiteStopped(); + + RestoreAppHostConfig(); } private async Task WaitUntilSiteStopped() @@ -145,8 +156,11 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting { if (site.State == ObjectState.Stopped) { - _logger.LogInformation($"Site {WebSiteName} has stopped successfully."); - return; + if (HostProcess.HasExited) + { + _logger.LogInformation($"Site {WebSiteName} has stopped successfully."); + return; + } } } catch (COMException) @@ -275,6 +289,20 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting return config; } + private void StopSite() + { + var site = _serverManager.Sites.Where(sites => sites.Name == WebSiteName).SingleOrDefault(); + + site.Stop(); + } + + private void StopAppPool() + { + var appPool = _serverManager.ApplicationPools.Where(pool => pool.Name == AppPoolName).SingleOrDefault(); + + appPool.Stop(); + } + private void SetGlobalModuleSection(Configuration config, string dllRoot) { var ancmFile = GetAncmLocation(dllRoot); diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs index 18b8e5d2ea..ffbc8ba034 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs @@ -106,7 +106,11 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS 5, 200); - Logger.LogInformation($"Found debug log file: {file}"); + if (arr.Length == 0) + { + Logger.LogWarning($"{file} is empty."); + } + foreach (var line in arr) { Logger.LogInformation(line);