diff --git a/tests/Avalonia.RenderTests/TestBase.cs b/tests/Avalonia.RenderTests/TestBase.cs index af4500e87f..81474d5efb 100644 --- a/tests/Avalonia.RenderTests/TestBase.cs +++ b/tests/Avalonia.RenderTests/TestBase.cs @@ -31,7 +31,7 @@ namespace Avalonia.Skia.RenderTests namespace Avalonia.Direct2D1.RenderTests #endif { - public class TestBase + public class TestBase : IDisposable { #if AVALONIA_SKIA private static string s_fontUri = "resm:Avalonia.Skia.RenderTests.Assets?assembly=Avalonia.Skia.RenderTests#Noto Mono"; @@ -282,5 +282,13 @@ namespace Avalonia.Direct2D1.RenderTests }); } } + + public void Dispose() + { + if (Dispatcher.UIThread.CheckAccess()) + { + Dispatcher.UIThread.RunJobs(); + } + } } } diff --git a/tests/Avalonia.UnitTests/TestWithServicesBase.cs b/tests/Avalonia.UnitTests/TestWithServicesBase.cs index bbd6c7427c..6f44aef1ba 100644 --- a/tests/Avalonia.UnitTests/TestWithServicesBase.cs +++ b/tests/Avalonia.UnitTests/TestWithServicesBase.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Avalonia.Threading; namespace Avalonia.UnitTests { @@ -17,6 +18,11 @@ namespace Avalonia.UnitTests public void Dispose() { + if (Dispatcher.UIThread.CheckAccess()) + { + Dispatcher.UIThread.RunJobs(); + } + _scope.Dispose(); } } diff --git a/tests/Avalonia.UnitTests/UnitTestApplication.cs b/tests/Avalonia.UnitTests/UnitTestApplication.cs index 620f301565..fe7f9712b4 100644 --- a/tests/Avalonia.UnitTests/UnitTestApplication.cs +++ b/tests/Avalonia.UnitTests/UnitTestApplication.cs @@ -46,6 +46,11 @@ namespace Avalonia.UnitTests Dispatcher.UIThread.UpdateServices(); return Disposable.Create(() => { + if (Dispatcher.UIThread.CheckAccess()) + { + Dispatcher.UIThread.RunJobs(); + } + scope.Dispose(); Dispatcher.UIThread.UpdateServices(); });