mirror of
https://github.com/PrismLibrary/Prism.git
synced 2026-10-28 12:48:32 +08:00
Unchanged master: observer fixture has 2 collection failures and 2 passing controls; WPF lifetime fixtures have 5 failures and 4 passing controls. Covers abandoned tracker, disposed-manager collection, loader replacement, disposal order, late callbacks and nested observer recreation. # Conflicts: # tests/Avalonia/Prism.Avalonia.Tests/Prism.Avalonia.Tests.csproj # tests/Wpf/Prism.Wpf.Tests/Prism.Wpf.Tests.csproj
26 lines
629 B
C#
26 lines
629 B
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using Xunit;
|
|
|
|
namespace Prism.Tests.Lifetime;
|
|
|
|
internal static class CollectionProbe
|
|
{
|
|
// Read weak targets only after all collections, outside the lifetime helper.
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
internal static void Collect()
|
|
{
|
|
for (var i = 0; i < 3; i++)
|
|
{
|
|
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
|
|
GC.WaitForPendingFinalizers();
|
|
}
|
|
}
|
|
|
|
internal static void Collected(WeakReference reference)
|
|
{
|
|
Collect();
|
|
Assert.False(reference.IsAlive);
|
|
}
|
|
}
|