Skip to content

Commit

Permalink
[tests] Add more logging to pinpoint hang (#104982)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdh1418 authored Jul 17, 2024
1 parent 8602bb3 commit 8a7e38e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tests/Loader/binding/tracing/BinderEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public BindOperation[] WaitAndGetEventsForAssembly(AssemblyName assemblyName)
}
}

Console.WriteLine($"Waiting for bind events for {assemblyName.Name} ({timeWaitedInMs}ms waited) Sleeping for {waitIntervalInMs}ms");
Thread.Sleep(waitIntervalInMs);
timeWaitedInMs += waitIntervalInMs;

Expand Down
4 changes: 4 additions & 0 deletions src/tests/Loader/binding/tracing/BinderTracingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private static bool RunSingleTest(MethodInfo method)
Func<BindOperation> func = (Func<BindOperation>)method.CreateDelegate(typeof(Func<BindOperation>));
using (var listener = new BinderEventListener(loadsToTrack))
{
Console.WriteLine($"[{DateTime.Now:T}] Invoking {method.Name}...");
BindOperation expected = func();
ValidateSingleBind(listener, expected.AssemblyName, expected);
}
Expand All @@ -182,6 +183,7 @@ private static bool RunSingleTest(MethodInfo method)
return false;
}

Console.WriteLine($"Test {method.Name} finished.");
return true;
}

Expand All @@ -197,6 +199,7 @@ private static bool RunTestInSeparateProcess(MethodInfo method)
Console.WriteLine($"[{DateTime.Now:T}] Launching process for {method.Name}...");
using (Process p = Process.Start(startInfo))
{
Console.WriteLine($"Started subprocess {p.Id} for {method.Name}...");
p.OutputDataReceived += (_, args) => Console.WriteLine(args.Data);
p.BeginOutputReadLine();

Expand All @@ -210,6 +213,7 @@ private static bool RunTestInSeparateProcess(MethodInfo method)

private static void ValidateSingleBind(BinderEventListener listener, AssemblyName assemblyName, BindOperation expected)
{
Console.WriteLine($"[{DateTime.Now:T}] Validating bind operation for {assemblyName}...");
BindOperation[] binds = listener.WaitAndGetEventsForAssembly(assemblyName);
Assert.True(binds.Length == 1, $"Bind event count for {assemblyName} - expected: 1, actual: {binds.Length}");
BindOperation actual = binds[0];
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Loader/binding/tracing/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class Helpers
{
public static void ValidateBindOperation(BindOperation expected, BindOperation actual)
{
Console.WriteLine("ValidateBindOperation Started");
ValidateAssemblyName(expected.AssemblyName, actual.AssemblyName, nameof(BindOperation.AssemblyName));
Assert.Equal(expected.AssemblyPath ?? string.Empty, actual.AssemblyPath);
Assert.Equal(expected.AssemblyLoadContext, actual.AssemblyLoadContext);
Expand All @@ -37,6 +38,7 @@ public static void ValidateBindOperation(BindOperation expected, BindOperation a
ValidateProbedPaths(expected.ProbedPaths, actual.ProbedPaths);

ValidateNestedBinds(expected.NestedBinds, actual.NestedBinds);
Console.WriteLine("ValidateBindOperation Finished");
}

public static string GetAssemblyInAppPath(string assemblyName)
Expand Down

0 comments on commit 8a7e38e

Please sign in to comment.