Check what current processes are running to see if dotnet.exe/iisexpress.exe is being stopped. (#1530)

This commit is contained in:
Justin Kotalik 2018-10-23 11:23:36 -07:00 committed by GitHub
parent 61f1a70784
commit 3842779379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 20 deletions

View File

@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
Assert.True(File.Exists(Path.Combine(deploymentResult.ContentRoot, "InProcessWebSite.exe")));
Assert.False(File.Exists(Path.Combine(deploymentResult.ContentRoot, "hostfxr.dll")));
Assert.Contains("InProcessWebSite.exe", File.ReadAllText(Path.Combine(deploymentResult.ContentRoot, "web.config")));
Assert.Contains("InProcessWebSite.exe", Helpers.ReadAllTextFromFile(Path.Combine(deploymentResult.ContentRoot, "web.config"), Logger));
await deploymentResult.AssertStarts();
}

View File

@ -13,26 +13,15 @@ using Xunit;
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
{
[Collection(PublishedSitesCollection.Name)]
public class LoggingTests : IISFunctionalTestBase
public class LoggingTests : LogFileTestBase
{
private readonly PublishedSitesFixture _fixture;
private readonly string _logFolderPath;
public LoggingTests(PublishedSitesFixture fixture)
{
_logFolderPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
_fixture = fixture;
}
public override void Dispose()
{
base.Dispose();
if (Directory.Exists(_logFolderPath))
{
Directory.Delete(_logFolderPath, true);
}
}
public static TestMatrix TestVariants
=> TestMatrix.ForServers(DeployerSelector.ServerType)
.WithTfms(Tfm.NetCoreApp22)
@ -65,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
StopServer();
var contents = File.ReadAllText(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath));
var contents = Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger);
Assert.Contains("TEST MESSAGE", contents);
}
@ -158,7 +147,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
var response = await deploymentResult.HttpClient.GetAsync("/");
StopServer();
var logContents = File.ReadAllText(firstTempFile);
var logContents = Helpers.ReadAllTextFromFile(firstTempFile, Logger);
Assert.Contains("Switching debug log files to", logContents);
AssertLogs(secondTempFile);
@ -202,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
StopServer();
var contents = File.ReadAllText(Helpers.GetExpectedLogName(deploymentResult, logFolderPath));
var contents = Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, logFolderPath), Logger);
Assert.Contains("彡⾔", contents);
if (variant.HostingModel == HostingModel.InProcess)

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
@ -209,5 +210,29 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
Path.Combine(deploymentResult.DeploymentParameters.PublishedApplicationRootPath, "aspnetcore-debug.log"),
"Running test allowed log file to be empty." + Environment.NewLine);
}
public static string ReadAllTextFromFile(string filename, ILogger logger)
{
try
{
return File.ReadAllText(filename);
}
catch (Exception ex)
{
// check if there is a dotnet.exe, iisexpress.exe, or w3wp.exe processes still running.
var hostingProcesses = Process.GetProcessesByName("dotnet")
.Concat(Process.GetProcessesByName("iisexpress"))
.Concat(Process.GetProcessesByName("w3wp"));
logger.LogError($"Could not read file content. Exception message {ex.Message}");
logger.LogError("Current hosting exes running:");
foreach (var hostingProcess in hostingProcesses)
{
logger.LogError($"{hostingProcess.ProcessName} pid: {hostingProcess.Id} hasExited: {hostingProcess.HasExited.ToString()}");
}
throw ex;
}
}
}
}

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities
public string GetLogFileContent(IISDeploymentResult deploymentResult)
{
return File.ReadAllText(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath));
return Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger);
}
}
}

View File

@ -61,7 +61,7 @@ namespace IIS.FunctionalTests.Inprocess
StopServer();
var contents = File.ReadAllText(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath));
var contents = Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger);
var expectedString = "The specified framework 'Microsoft.NETCore.App', version '2.9.9' was not found.";
EventLogHelpers.VerifyEventLogEvent(deploymentResult, expectedString);
Assert.Contains(expectedString, contents);
@ -88,7 +88,7 @@ namespace IIS.FunctionalTests.Inprocess
StopServer();
var fileInDirectory = Directory.GetFiles(_logFolderPath).Single();
var contents = File.ReadAllText(fileInDirectory);
var contents = Helpers.ReadAllTextFromFile(fileInDirectory, Logger);
EventLogHelpers.VerifyEventLogEvent(deploymentResult, "Invoked hostfxr");
Assert.Contains("Invoked hostfxr", contents);
}
@ -141,7 +141,7 @@ namespace IIS.FunctionalTests.Inprocess
StopServer();
var fileInDirectory = Directory.GetFiles(_logFolderPath).First();
var contents = File.ReadAllText(fileInDirectory);
var contents = Helpers.ReadAllTextFromFile(fileInDirectory, Logger);
EventLogHelpers.VerifyEventLogEvent(deploymentResult, "Invoked hostfxr");
Assert.Contains("Invoked hostfxr", contents);