Skip to content

Commit

Permalink
Disable weak collection debug tests on netfw
Browse files Browse the repository at this point in the history
  • Loading branch information
mikernet committed Mar 12, 2024
1 parent 7c45272 commit f618126
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Tests/Singulink.Collections.Weak.Tests/GCTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Singulink.Collections.Weak.Tests;

#if NET || RELEASE

[PrefixTestClass]
public class GCTests
{
Expand All @@ -13,4 +15,6 @@ public void EnterNoGCRegionAndCollect()
Helpers.CollectAndWait();
weakRef.TryGetTarget(out _).ShouldBeFalse();
}
}
}

#endif
14 changes: 11 additions & 3 deletions Tests/Singulink.Collections.Weak.Tests/NoGCRegion.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#pragma warning disable CA1815 // Override equals and operator equals on value types

using System.Runtime.CompilerServices;

namespace Singulink.Collections.Weak.Tests;

public struct NoGCRegion : IDisposable
#if NET || RELEASE

public readonly struct NoGCRegion : IDisposable
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static NoGCRegion Enter(long memoryNeeded)
{
for (int i = 0; i < 1000; i++)
Expand All @@ -14,11 +19,14 @@ public static NoGCRegion Enter(long memoryNeeded)
Thread.Sleep(1);
}

throw new InvalidOperationException("Could not enter no GC region.");
throw new InvalidOperationException("Failed to enter no GC region.");
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
GC.EndNoGCRegion();
}
}
}

#endif
4 changes: 4 additions & 0 deletions Tests/Singulink.Collections.Weak.Tests/WeakCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Singulink.Collections.Weak.Tests;

#if NET || RELEASE

[PrefixTestClass]
public class WeakCollectionTests
{
Expand Down Expand Up @@ -88,3 +90,5 @@ private static void AddCollectableItems(WeakCollection<object> c, int count)
c.Add(new object());
}
}

#endif
4 changes: 4 additions & 0 deletions Tests/Singulink.Collections.Weak.Tests/WeakListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Singulink.Collections.Weak.Tests;

#if NET || RELEASE

[PrefixTestClass]
public class WeakListTests
{
Expand Down Expand Up @@ -50,3 +52,5 @@ private static void AddCollectableItems(WeakList<object> c, int count)
c.Add(new object());
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Singulink.Collections.Weak.Tests;

#if NET || RELEASE

[PrefixTestClass]
public class WeakValueDictionaryTests
{
Expand Down Expand Up @@ -97,3 +99,5 @@ private static void AddCollectableItems(WeakValueDictionary<int, object> c, int
c.Add(startKey++, new object());
}
}

#endif

0 comments on commit f618126

Please sign in to comment.