diff --git a/src/libraries/System.Buffers/tests/ArrayPool/ArrayPoolTest.cs b/src/libraries/System.Buffers/tests/ArrayPool/ArrayPoolTest.cs index 01fb4d819f576..754814d41ca58 100644 --- a/src/libraries/System.Buffers/tests/ArrayPool/ArrayPoolTest.cs +++ b/src/libraries/System.Buffers/tests/ArrayPool/ArrayPoolTest.cs @@ -10,8 +10,6 @@ namespace System.Buffers.ArrayPool.Tests { public abstract class ArrayPoolTest { - protected const string TrimSwitchName = "DOTNET_SYSTEM_BUFFERS_ARRAYPOOL_TRIMSHARED"; - protected static class EventIds { public const int BufferRented = 1; @@ -35,16 +33,7 @@ protected static int RunWithListener(Action body, EventLevel level, Action method, bool trim = false, int timeout = RemoteExecutor.FailWaitTimeoutMilliseconds) + protected static void RemoteInvokeWithTrimming(Action method, int timeout = RemoteExecutor.FailWaitTimeoutMilliseconds) { var options = new RemoteInvokeOptions { @@ -52,9 +41,8 @@ protected static void RemoteInvokeWithTrimming(Action method, bool trim }; options.StartInfo.UseShellExecute = false; - options.StartInfo.EnvironmentVariables.Add(TrimSwitchName, trim.ToString()); - RemoteExecutor.Invoke(method, trim.ToString(), options).Dispose(); + RemoteExecutor.Invoke(method, options).Dispose(); } } } diff --git a/src/libraries/System.Buffers/tests/ArrayPool/CollectionTests.cs b/src/libraries/System.Buffers/tests/ArrayPool/CollectionTests.cs index d29e1c7141698..6b39f5409bdea 100644 --- a/src/libraries/System.Buffers/tests/ArrayPool/CollectionTests.cs +++ b/src/libraries/System.Buffers/tests/ArrayPool/CollectionTests.cs @@ -15,22 +15,16 @@ namespace System.Buffers.ArrayPool.Tests public class CollectionTests : ArrayPoolTest { [OuterLoop("This is a long running test (over 2 minutes)")] - [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported)), - InlineData(true), - InlineData(false)] - public void BuffersAreCollectedWhenStale(bool trim) + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public void BuffersAreCollectedWhenStale() { - RemoteInvokeWithTrimming((trimString) => + RemoteInvokeWithTrimming(() => { - // Check that our environment is as we expect - Assert.Equal(trimString, Environment.GetEnvironmentVariable(TrimSwitchName)); - const int BufferCount = 8; const int BufferSize = 1025; // Get the pool and check our trim setting var pool = ArrayPool.Shared; - bool parsedTrim = ValidateTrimState(pool, trimString); List rentedBuffers = new List(); @@ -71,27 +65,21 @@ public void BuffersAreCollectedWhenStale(bool trim) } // Should only have found a new buffer if we're trimming - Assert.Equal(parsedTrim, foundNewBuffer); - }, trim, 3 * 60 * 1000); // This test has to wait for the buffers to go stale (give it three minutes) + Assert.True(foundNewBuffer); + }, 3 * 60 * 1000); // This test has to wait for the buffers to go stale (give it three minutes) } private static bool IsStressModeEnabledAndRemoteExecutorSupported => TestEnvironment.IsStressModeEnabled && RemoteExecutor.IsSupported; // This test can cause problems for other tests run in parallel (from other assemblies) as // it pushes the physical memory usage above 80% temporarily. - [ConditionalTheory(nameof(IsStressModeEnabledAndRemoteExecutorSupported)), - InlineData(true), - InlineData(false)] - public unsafe void ThreadLocalIsCollectedUnderHighPressure(bool trim) + [ConditionalFact(nameof(IsStressModeEnabledAndRemoteExecutorSupported))] + public unsafe void ThreadLocalIsCollectedUnderHighPressure() { - RemoteInvokeWithTrimming((trimString) => + RemoteInvokeWithTrimming(() => { - // Check that our environment is as we expect - Assert.Equal(trimString, Environment.GetEnvironmentVariable(TrimSwitchName)); - // Get the pool and check our trim setting var pool = ArrayPool.Shared; - bool parsedTrim = ValidateTrimState(pool, trimString); // Create our buffer, return it, re-rent it and ensure we have the same one const int BufferSize = 4097; @@ -119,40 +107,21 @@ public unsafe void ThreadLocalIsCollectedUnderHighPressure(bool trim) } while ((int)pressureMethod.Invoke(null, null) != 2); GC.WaitForPendingFinalizers(); - if (parsedTrim) - { - // Should have a new buffer now - Assert.NotSame(buffer, pool.Rent(BufferSize)); - } - else - { - // Disabled, should not have trimmed buffer - Assert.Same(buffer, pool.Rent(BufferSize)); - } - }, trim); - } - private static bool ValidateTrimState(object pool, string trimString) - { - Assert.StartsWith("TlsOverPerCoreLockedStacksArrayPool", pool.GetType().Name); - bool parsedTrim = bool.Parse(trimString); - var trimField = pool.GetType().GetField("s_trimBuffers", BindingFlags.Static | BindingFlags.NonPublic); - Assert.Equal(parsedTrim, (bool)trimField.GetValue(null)); - return parsedTrim; + // Should have a new buffer now + Assert.NotSame(buffer, pool.Rent(BufferSize)); + }); } private static bool IsPreciseGcSupportedAndRemoteExecutorSupported => PlatformDetection.IsPreciseGcSupported && RemoteExecutor.IsSupported; [ActiveIssue("https://github.com/dotnet/runtime/issues/44037")] - [ConditionalTheory(nameof(IsPreciseGcSupportedAndRemoteExecutorSupported))] - [InlineData(true)] - [InlineData(false)] - public void PollingEventFires(bool trim) + [ConditionalFact(nameof(IsPreciseGcSupportedAndRemoteExecutorSupported))] + public void PollingEventFires() { - RemoteInvokeWithTrimming((trimString) => + RemoteInvokeWithTrimming(() => { var pool = ArrayPool.Shared; - bool parsedTrim = ValidateTrimState(pool, trimString); bool pollEventFired = false; var buffer = pool.Rent(10); @@ -187,8 +156,8 @@ public void PollingEventFires(bool trim) }); // Polling events should only fire when trimming is enabled - Assert.Equal(parsedTrim, pollEventFired); - }, trim); + Assert.True(pollEventFired); + }); } } } diff --git a/src/libraries/System.Buffers/tests/ArrayPool/UnitTests.cs b/src/libraries/System.Buffers/tests/ArrayPool/UnitTests.cs index 5673d22d36393..84246f7d170cd 100644 --- a/src/libraries/System.Buffers/tests/ArrayPool/UnitTests.cs +++ b/src/libraries/System.Buffers/tests/ArrayPool/UnitTests.cs @@ -355,7 +355,6 @@ public static void RentingGiganticArraySucceeds(int length, bool expectPooled) { var options = new RemoteInvokeOptions(); options.StartInfo.UseShellExecute = false; - options.StartInfo.EnvironmentVariables.Add(TrimSwitchName, "false"); RemoteExecutor.Invoke((lengthStr, expectPooledStr) => {