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..90f13403818274 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,16 @@ 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 System.Threading.Tasks; using MonoTests.Common; +using Xunit; namespace MonoTests.System.Runtime.Caching { @@ -84,7 +86,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; @@ -132,7 +133,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; @@ -148,9 +148,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 +201,12 @@ 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 +246,48 @@ public void UniqueId() CleanupMonitoring(setup); } } + + [OuterLoop] + [Fact] + public async Task 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 - 5s should be more than enough + var delay = 5000; + var inc = 50; + for (int i = 0; i < delay; i += inc) + { + if (!mc.Contains("key")) + break; + await Task.Delay(inc); + } + + Assert.Null(mc["key"]); + } + finally + { + CleanupMonitoring(setup); + } + } } } 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..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 @@ -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); @@ -1109,9 +1108,7 @@ 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))] + [Theory] [InlineData("true"), InlineData("false"), InlineData(null)] public void Trim(string throwOnDisposed) { @@ -1197,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(); @@ -1510,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; @@ -1570,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();