Skip to content

Commit

Permalink
Further logging to diagnose test failure in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tintoy committed Oct 31, 2019
1 parent 09c3313 commit 041d301
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/LanguageServer.Common/Utilities/DotNetRuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ public class DotNetRuntimeInfo
/// <param name="baseDirectory">
/// An optional base directory where dotnet.exe should be run (this may affect the version it reports due to global.json).
/// </param>
/// <param name="logger">
/// An optional logger to use for diagnostic purposes (if not specified, the static <see cref="Log.Logger"/> will be used).
/// </param>
/// <returns>
/// A <see cref="DotNetRuntimeInfo"/> containing the runtime information.
/// </returns>
public static DotNetRuntimeInfo GetCurrent(string baseDirectory = null)
public static DotNetRuntimeInfo GetCurrent(string baseDirectory = null, ILogger logger = null)
{
if (logger == null)
logger = Log.Logger;

DotNetRuntimeInfo runtimeInfo = new DotNetRuntimeInfo();

Process dotnetInfoProcess = new Process
Expand Down Expand Up @@ -74,11 +80,11 @@ public static DotNetRuntimeInfo GetCurrent(string baseDirectory = null)
}
};

Log.Debug("Launching {Command}...", command);
logger.Debug("Launching {Command}...", command);

dotnetInfoProcess.Start();

Log.Debug("Launched {Command}. Waiting for process {TargetProcessId} to terminate...", command, dotnetInfoProcess.Id);
logger.Debug("Launched {Command}. Waiting for process {TargetProcessId} to terminate...", command, dotnetInfoProcess.Id);

// Asynchronously start reading from STDOUT / STDERR.
dotnetInfoProcess.BeginOutputReadLine();
Expand All @@ -90,25 +96,25 @@ public static DotNetRuntimeInfo GetCurrent(string baseDirectory = null)
}
catch (TimeoutException exitTimedOut)
{
Log.Error(exitTimedOut, "Timed out after waiting 5 seconds for {Command} to exit.", command);
logger.Error(exitTimedOut, "Timed out after waiting 5 seconds for {Command} to exit.", command);

throw new TimeoutException($"Timed out after waiting 5 seconds for '{command}' to exit.", exitTimedOut);
}

Log.Debug("{Command} terminated with exit code {ExitCode}.", command, dotnetInfoProcess.ExitCode);
logger.Debug("{Command} terminated with exit code {ExitCode}.", command, dotnetInfoProcess.ExitCode);

string processOutput;
lock (localOutputBuffer)
{
processOutput = localOutputBuffer.ToString();
}

if ( Log.IsEnabled(Serilog.Events.LogEventLevel.Verbose) )
if ( logger.IsEnabled(Serilog.Events.LogEventLevel.Verbose) )
{
if (!String.IsNullOrWhiteSpace(processOutput))
Log.Debug("{Command} returned the following text on STDOUT / STDERR.\n\n{DotNetInfoOutput:l}", command, processOutput);
logger.Debug("{Command} returned the following text on STDOUT / STDERR.\n\n{DotNetInfoOutput:l}", command, processOutput);
else
Log.Debug("{Command} returned no output on STDOUT / STDERR.");
logger.Debug("{Command} returned no output on STDOUT / STDERR.");
}

using (StringReader bufferReader = new StringReader(processOutput))
Expand Down
5 changes: 5 additions & 0 deletions test/LanguageServer.Engine.Tests/MSBuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class MSBuildTests
public MSBuildTests(ITestOutputHelper testOutput)
: base(testOutput)
{
// For CI-diagnostic purposes.
LogLevelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Verbose;
}

// TODO: More realistic tests for working with MSBuild evaluation projects.
Expand All @@ -46,6 +48,9 @@ public MSBuildTests(ITestOutputHelper testOutput)
[Theory(DisplayName = "Dump all UsingTask elements in an MSBuild project ")]
public void DumpUsingTasks(string projectName)
{
// For CI-diagnostic purposes.
DotNetRuntimeInfo.GetCurrent(logger: Log);

Project project = LoadTestProject(projectName + ".csproj");
using (project.ProjectCollection)
{
Expand Down

0 comments on commit 041d301

Please sign in to comment.