Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.Runtime.InteropServices
public class HandleCollectorTests
{
private const int LowLimitSize = 20;
private const int HighLimitSize = 100000;
private const int HighLimitSize = 100_000;

[Theory]
[InlineData(null, 0)]
Expand Down Expand Up @@ -128,6 +128,7 @@ public static void TestHandleCollector()
for (int i = 0; i < LowLimitSize + 1; ++i)
{
HandleLimitTester hlt = new HandleLimitTester(lowLimitCollector);
Assert.True(lowLimitCollector.Count <= i + 1);
}

// HandleLimitTester does the decrement on the HandleCollector during finalization, so we wait for pending finalizers.
Expand All @@ -142,6 +143,7 @@ public static void TestHandleCollector()
for (int i = 0; i < HighLimitSize + 10; ++i)
{
HandleLimitTester hlt = new HandleLimitTester(highLimitCollector);
Assert.True(highLimitCollector.Count <= i + 1);
}

// HandleLimitTester does the decrement on the HandleCollector during finalization, so we wait for pending finalizers.
Expand All @@ -155,11 +157,13 @@ public static void TestHandleCollector()

private sealed class HandleLimitTester
{
private HandleCollector _collector;
private readonly HandleCollector _collector;
private readonly int[] _pressure;

internal HandleLimitTester(HandleCollector collector)
{
_collector = collector;
_pressure = new int[1_000];
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
_collector.Add();
GC.KeepAlive(this);
}
Expand Down