From 2dda94362fd5ea91745dae3b021c7fc11df743ca Mon Sep 17 00:00:00 2001 From: Steve Molloy Date: Mon, 21 Jul 2025 13:06:11 -0700 Subject: [PATCH 1/4] Test re-enabling SRC cache tests. --- .../tests/System.Runtime.Caching/MemoryCacheTest.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs index 5550b59c4d88ef..3f4980184e8059 100644 --- a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs +++ b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs @@ -304,7 +304,6 @@ public void Indexer(string throwOnDisposed) } [Theory, InlineData("true"), InlineData("false"), InlineData(null)] - //[ActiveIssue("https://github.com/dotnet/runtime/issues/1429")] public void Contains(string throwOnDisposed) { var mc = CreatePokerMemoryCache("MyCache", throwOnDisposed); @@ -1111,7 +1110,9 @@ public void ChangeMonitors() // Due to internal implementation details Trim has very few easily verifiable scenarios // ActiveIssue: https://github.com/dotnet/runtime/issues/36488 - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] + //[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] + //https://github.com/dotnet/runtime/pull/36494/files + [Theory] [InlineData("true"), InlineData("false"), InlineData(null)] public void Trim(string throwOnDisposed) { @@ -1201,7 +1202,7 @@ public void TestExpiredGetValues() // runtime binary on the wrong OS. Without it, this test will run for each 'TargetFramework' // in the test csproj, and the non-windows framework will run against the non-windows library // because 'netstandard' is still valid for windows execution. - [PlatformSpecific(TestPlatforms.Windows)] + //[PlatformSpecific(TestPlatforms.Windows)] public void TestCacheSliding() { var config = new NameValueCollection(); @@ -1510,7 +1511,7 @@ public class MemoryCacheTestExpires4 public static bool SupportsPhysicalMemoryMonitor => MemoryCacheTest.SupportsPhysicalMemoryMonitor; [ConditionalFact(nameof(SupportsPhysicalMemoryMonitor))] - [SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93106")] + //[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93106")] public async Task TestCacheShrink() { const int HEAP_RESIZE_THRESHOLD = 8192 + 2; @@ -1570,7 +1571,7 @@ public class MemoryCacheTestExpires5 public static bool SupportsPhysicalMemoryMonitor => MemoryCacheTest.SupportsPhysicalMemoryMonitor; [ConditionalFact(nameof(SupportsPhysicalMemoryMonitor))] - [SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93106")] + //[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93106")] public async Task TestCacheExpiryOrdering() { var config = new NameValueCollection(); From 20083f53dfba33a0a021fb52863e6566b8e9cff4 Mon Sep 17 00:00:00 2001 From: Steve Molloy Date: Tue, 22 Jul 2025 17:21:26 -0700 Subject: [PATCH 2/4] Enable some more tests. Add one for file change monitoring. --- .../HostFileChangeMonitorTest.cs | 59 ++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs index c9d83355d6c1a6..251d2587ec7d98 100644 --- a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs +++ b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs @@ -30,14 +30,15 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.IO; using System.Reflection; using System.Runtime.Caching; using System.Runtime.Caching.Hosting; using System.Text; - -using Xunit; +using System.Threading; using MonoTests.Common; +using Xunit; namespace MonoTests.System.Runtime.Caching { @@ -84,7 +85,7 @@ public void Constructor_Exceptions() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] + //[ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] public static void Constructor_MissingFiles_Handler() { HostFileChangeMonitor monitor; @@ -132,7 +133,7 @@ public static void Constructor_MissingFiles_Handler() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] + //[ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] public void Constructor_Duplicates() { HostFileChangeMonitor monitor; @@ -148,9 +149,9 @@ public void Constructor_Duplicates() monitor.Dispose(); } - private static Tuple> SetupMonitoring() + private static Tuple> SetupMonitoring(string uniqueId) { - string testPath = Path.Combine(Path.GetTempPath(), "HostFileChangeMonitorTest", "Dispose_Calls_StopMonitoring"); + string testPath = Path.Combine(Path.GetTempPath(), "HostFileChangeMonitorTest", uniqueId); if (!Directory.Exists(testPath)) Directory.CreateDirectory(testPath); @@ -201,13 +202,13 @@ private static void CleanupMonitoring(Tuple> setup = null; try { - setup = SetupMonitoring(); + setup = SetupMonitoring(nameof(UniqueId)); FileInfo fi; var monitor = new HostFileChangeMonitor(setup.Item4); var sb = new StringBuilder(); @@ -247,5 +248,47 @@ public void UniqueId() CleanupMonitoring(setup); } } + + [Fact] +// [OuterLoop] // TODO - make this outter loop before merging + //[ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] + public void Reasonable_Delay() + { + Tuple> setup = null; + try + { + setup = SetupMonitoring(nameof(Reasonable_Delay)); + + using var monitor = new HostFileChangeMonitor(setup.Item4); + var policy = new CacheItemPolicy + { + ChangeMonitors = { monitor } + }; + var config = new NameValueCollection(); + var mc = new PokerMemoryCache("MyCache", config); + + mc.Set("key", "value", policy); + + // Verify the cache item is set + Assert.Equal("value", mc["key"]); + + // Update the file dependency + File.WriteAllText(setup.Item2, "I am the first file. Updated."); + + // Wait for the monitor to detect the change - 100ms should be plenty + for (int i = 0; i < 10; i++) + { + if (!mc.Contains("key")) + break; + Thread.Sleep(10); + } + + Assert.Null(mc["key"]); + } + finally + { + CleanupMonitoring(setup); + } + } } } From cb66180cafb047e2c562cdfd46767776c93f48fa Mon Sep 17 00:00:00 2001 From: Steve Molloy Date: Wed, 23 Jul 2025 08:45:31 -0700 Subject: [PATCH 3/4] Allow a little more time on timing test for robustness. --- .../System.Runtime.Caching/HostFileChangeMonitorTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs index 251d2587ec7d98..b4979fcf7bd789 100644 --- a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs +++ b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs @@ -275,12 +275,12 @@ public void Reasonable_Delay() // Update the file dependency File.WriteAllText(setup.Item2, "I am the first file. Updated."); - // Wait for the monitor to detect the change - 100ms should be plenty - for (int i = 0; i < 10; i++) + // Wait for the monitor to detect the change - 5s should be more than enough + for (int i = 0; i < 250; i++) { if (!mc.Contains("key")) break; - Thread.Sleep(10); + Thread.Sleep(20); } Assert.Null(mc["key"]); From eb9f506419082441538c73b01a1d7cc0ab758eca Mon Sep 17 00:00:00 2001 From: Steve Molloy Date: Mon, 4 Aug 2025 10:56:31 -0700 Subject: [PATCH 4/4] Cleanup temp-comments; re-enable outerloop --- .../HostFileChangeMonitorTest.cs | 6 +----- .../tests/System.Runtime.Caching/MemoryCacheTest.cs | 11 ----------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs index b4979fcf7bd789..bf9b16e25aa765 100644 --- a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs +++ b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/HostFileChangeMonitorTest.cs @@ -85,7 +85,6 @@ public void Constructor_Exceptions() } [Fact] - //[ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] public static void Constructor_MissingFiles_Handler() { HostFileChangeMonitor monitor; @@ -133,7 +132,6 @@ public static void Constructor_MissingFiles_Handler() } [Fact] - //[ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] public void Constructor_Duplicates() { HostFileChangeMonitor monitor; @@ -202,7 +200,6 @@ private static void CleanupMonitoring(Tuple> setup = null; @@ -249,9 +246,8 @@ public void UniqueId() } } + [OuterLoop] [Fact] -// [OuterLoop] // TODO - make this outter loop before merging - //[ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] public void Reasonable_Delay() { Tuple> setup = null; diff --git a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs index 3f4980184e8059..27db018c16bf0a 100644 --- a/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs +++ b/src/libraries/System.Runtime.Caching/tests/System.Runtime.Caching/MemoryCacheTest.cs @@ -1108,10 +1108,6 @@ public void ChangeMonitors() Assert.False(onChangedCalled); } - // Due to internal implementation details Trim has very few easily verifiable scenarios - // ActiveIssue: https://github.com/dotnet/runtime/issues/36488 - //[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] - //https://github.com/dotnet/runtime/pull/36494/files [Theory] [InlineData("true"), InlineData("false"), InlineData(null)] public void Trim(string throwOnDisposed) @@ -1198,11 +1194,6 @@ public void TestExpiredGetValues() [OuterLoop] // makes long wait [Fact] - // This little dance is needed to prevent this test from running against the OS-specific - // runtime binary on the wrong OS. Without it, this test will run for each 'TargetFramework' - // in the test csproj, and the non-windows framework will run against the non-windows library - // because 'netstandard' is still valid for windows execution. - //[PlatformSpecific(TestPlatforms.Windows)] public void TestCacheSliding() { var config = new NameValueCollection(); @@ -1511,7 +1502,6 @@ public class MemoryCacheTestExpires4 public static bool SupportsPhysicalMemoryMonitor => MemoryCacheTest.SupportsPhysicalMemoryMonitor; [ConditionalFact(nameof(SupportsPhysicalMemoryMonitor))] - //[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93106")] public async Task TestCacheShrink() { const int HEAP_RESIZE_THRESHOLD = 8192 + 2; @@ -1571,7 +1561,6 @@ public class MemoryCacheTestExpires5 public static bool SupportsPhysicalMemoryMonitor => MemoryCacheTest.SupportsPhysicalMemoryMonitor; [ConditionalFact(nameof(SupportsPhysicalMemoryMonitor))] - //[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93106")] public async Task TestCacheExpiryOrdering() { var config = new NameValueCollection();