From 9eaef28b31bbb878218a8206271a6969fdeec046 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 3 Jun 2020 10:02:03 -0700 Subject: [PATCH] Attempt to capture binlogs when test times out (#22468) --- .../IntegrationTests/MSBuildProcessManager.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildProcessManager.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildProcessManager.cs index 2f2ddc2d46..e9a9216782 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildProcessManager.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildProcessManager.cs @@ -50,7 +50,31 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests processStartInfo.EnvironmentVariables["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "true"; } - var processResult = await RunProcessCoreAsync(processStartInfo, timeout); + ProcessResult processResult; + try + { + processResult = await RunProcessCoreAsync(processStartInfo, timeout); + } + catch (TimeoutException ex) + { + // Copy the binlog to the artifacts directory if executing MSBuild throws. + // This would help diagnosing failures on the CI. + var binaryLogFile = Path.Combine(project.ProjectFilePath, "msbuild.binlog"); + + var artifactsLogDir = Assembly.GetExecutingAssembly() + .GetCustomAttributes() + .FirstOrDefault(ama => ama.Key == "ArtifactsLogDir")?.Value; + + if (!string.IsNullOrEmpty(artifactsLogDir) && File.Exists(binaryLogFile)) + { + var targetPath = Path.Combine(artifactsLogDir, Path.GetFileNameWithoutExtension(project.ProjectFilePath) + "." + Path.GetRandomFileName() + ".binlog"); + File.Copy(binaryLogFile, targetPath); + + throw new TimeoutException(ex.Message + $"{Environment.NewLine}Captured binlog at {targetPath}"); + } + + throw; + } return new MSBuildResult(project, processResult.FileName, processResult.Arguments, processResult.ExitCode, processResult.Output); }