提交 1238fc4a 编写于 作者: S Sam Harwell

Additional cleanup for WpfTestRunner

* Join the STA thread before completing the test (with a hang mitigating timeout)
* Update the STA thread name to reflect the current test method
上级 535ea382
......@@ -26,6 +26,11 @@ namespace Roslyn.Test.Utilities
/// </summary>
public sealed class WpfTestRunner : XunitTestRunner
{
/// <summary>
/// A long timeout used to avoid hangs in tests, where a test failure manifests as an operation never occurring.
/// </summary>
private static readonly TimeSpan HangMitigatingTimeout = TimeSpan.FromMinutes(1);
private static string s_wpfFactRequirementReason;
public WpfTestSharedData SharedData { get; }
......@@ -53,9 +58,10 @@ protected override Task<decimal> InvokeTestMethodAsync(ExceptionAggregator aggre
DispatcherSynchronizationContext synchronizationContext = null;
Dispatcher dispatcher = null;
Thread staThread;
using (var staThreadStartedEvent = new ManualResetEventSlim(initialState: false))
{
var staThread = new Thread((ThreadStart)(() =>
staThread = new Thread((ThreadStart)(() =>
{
// All WPF Tests need a DispatcherSynchronizationContext and we dont want to block pending keyboard
// or mouse input from the user. So use background priority which is a single level below user input.
......@@ -71,7 +77,7 @@ protected override Task<decimal> InvokeTestMethodAsync(ExceptionAggregator aggre
Dispatcher.Run();
}));
staThread.Name = nameof(WpfTestRunner);
staThread.Name = $"{nameof(WpfTestRunner)} {TestMethod.Name}";
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
......@@ -115,6 +121,9 @@ protected override Task<decimal> InvokeTestMethodAsync(ExceptionAggregator aggre
// are delayed and run during AppDomain or process shutdown, where they can lead to crashes of
// the test process.
dispatcher.InvokeShutdown();
// Join the STA thread, which ensures shutdown is complete.
staThread.Join(HangMitigatingTimeout);
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册