Browse Source

Merge pull request #10552 from AvaloniaUI/repro-test-issue

Fix Flaky Tests: Ensure that the dispatcher jobs queues are emptied after each test
pull/10555/head
Dan Walmsley 3 years ago
committed by GitHub
parent
commit
61751119ff
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      tests/Avalonia.RenderTests/TestBase.cs
  2. 6
      tests/Avalonia.UnitTests/TestWithServicesBase.cs
  3. 5
      tests/Avalonia.UnitTests/UnitTestApplication.cs

10
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();
}
}
}
}

6
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();
}
}

5
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();
});

Loading…
Cancel
Save