Skip to content

Commit

Permalink
capture screenshot on hang
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Aug 29, 2022
1 parent 9079576 commit af38f19
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Tools/Source/RunTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.Models;

namespace RunTests
{
Expand Down Expand Up @@ -99,7 +101,7 @@ private static async Task<int> RunAsync(Options options, TimeSpan timeout, Cance
{
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
var runTask = RunAsync(options, cts.Token);
var timeoutTask = Task.Delay(options.Timeout.Value, cancellationToken);
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

var finishedTask = await Task.WhenAny(timeoutTask, runTask);
if (finishedTask == timeoutTask)
Expand Down Expand Up @@ -253,6 +255,16 @@ async Task DumpProcess(Process targetProcess, string procDumpExeFilePath, string
}
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var screenshotPath = Path.Combine(options.LogFilesDirectory, "timeout.png");
ConsoleUtil.WriteLine($"Taking screenshot on timeout at {screenshotPath}");
var p = ProcessRunner.CreateProcess("Powershell.exe", $"-command \"& {{ . .\\eng\\build-utils-win.ps1; Capture-Screenshot {screenshotPath} }}\"");
var output = await p.Result;
ConsoleUtil.WriteLine(string.Join(Environment.NewLine, output.OutputLines));
ConsoleUtil.WriteLine(string.Join(Environment.NewLine, output.ErrorLines));
}

if (options.CollectDumps && !string.IsNullOrEmpty(options.ProcDumpFilePath))
{
ConsoleUtil.WriteLine("Roslyn Error: test timeout exceeded, dumping remaining processes");
Expand Down

0 comments on commit af38f19

Please sign in to comment.