Skip to content

Commit

Permalink
Fix tests (disable using clrmd for non-windows tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliya-usov committed Jan 12, 2024
1 parent ea3a06a commit f15c7b4
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions rd-net/Test.Lifetimes/Lifetimes/LifetimeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -293,6 +294,32 @@ void LoggerHandler(LeveledMessage message)
Assert.IsTrue(executionWasNotCancelledByTimeoutReceived);
Assert.IsTrue(receivedException.Message.Contains(stackTraceHeader), $"Exception `{expectedExceptionText}` doesn't contain {stackTraceHeader}");
Assert.IsTrue(receivedException.Message.Contains(nameof(WaitForLifetimeTerminatedEvent)), $"Exception `{expectedExceptionText}` doesn't contain {nameof(WaitForLifetimeTerminatedEvent)} method");

static string GetCurrentProcessThreadDumps()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// clrmd crashes the process if os is not Windows, so just return the name of the method
return nameof(WaitForLifetimeTerminatedEvent);
}

using var dataTarget = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, suspend: false);
var clrVersion = dataTarget.ClrVersions.SingleOrDefault() ?? throw new Exception("Failed to get single clr from current process");

using var runtime = clrVersion.CreateRuntime();
var output = new StringBuilder();
foreach (var clrThread in runtime.Threads)
{
if (!clrThread.IsAlive)
continue;
output.AppendLine($"Thread #{clrThread.ManagedThreadId}:");

foreach (var frame in clrThread.EnumerateStackTrace())
output.AppendLine($"\tat {frame}");
}

return output.ToString();
}
#endif
}

Expand All @@ -301,29 +328,7 @@ private static void WaitForLifetimeTerminatedEvent(ManualResetEvent lifetimeTerm
{
lifetimeTerminatedEvent.WaitOne();
}

#if !NET35
private static string GetCurrentProcessThreadDumps()
{
using var dataTarget = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, suspend:false);
var clrVersion = dataTarget.ClrVersions.SingleOrDefault() ?? throw new Exception("Failed to get single clr from current process");

using var runtime = clrVersion.CreateRuntime();
var output = new StringBuilder();
foreach (var clrThread in runtime.Threads)
{
if (!clrThread.IsAlive)
continue;
output.AppendLine($"Thread #{clrThread.ManagedThreadId}:");

foreach (var frame in clrThread.EnumerateStackTrace())
output.AppendLine($"\tat {frame}");
}

return output.ToString();
}
#endif


[Test]
public void TestBracketGood()
{
Expand Down

0 comments on commit f15c7b4

Please sign in to comment.