-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Re-enable tests for Sys.RT.Caching #118508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2dda943
20083f5
cb66180
eb9f506
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,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 +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; | ||
|
|
@@ -148,9 +147,9 @@ public void Constructor_Duplicates() | |
| monitor.Dispose(); | ||
| } | ||
|
|
||
| private static Tuple<string, string, string, IList<string>> SetupMonitoring() | ||
| private static Tuple<string, string, string, IList<string>> 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 +200,12 @@ private static void CleanupMonitoring(Tuple<string, string, string, IList<string | |
| } | ||
|
|
||
| [Fact] | ||
| [ActiveIssue("https://github.com/dotnet/runtime/issues/34497", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] | ||
| public void UniqueId() | ||
| { | ||
| Tuple<string, string, string, IList<string>> setup = null; | ||
| try | ||
| { | ||
| setup = SetupMonitoring(); | ||
| setup = SetupMonitoring(nameof(UniqueId)); | ||
| FileInfo fi; | ||
| var monitor = new HostFileChangeMonitor(setup.Item4); | ||
| var sb = new StringBuilder(); | ||
|
|
@@ -247,5 +245,46 @@ public void UniqueId() | |
| CleanupMonitoring(setup); | ||
| } | ||
| } | ||
|
|
||
| [OuterLoop] | ||
| [Fact] | ||
| public void Reasonable_Delay() | ||
| { | ||
| Tuple<string, string, string, IList<string>> 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 | ||
| for (int i = 0; i < 250; i++) | ||
| { | ||
| if (!mc.Contains("key")) | ||
| break; | ||
| Thread.Sleep(20); | ||
|
StephenMolloy marked this conversation as resolved.
|
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there are a lot of tests running in parallel (which xunit attempts to achieve), there can be a lot of thread contention and this might not return within 20ms. I would create a Stopwatch before the loop and use a while loop checking if the required amount of time has elapsed yet. This would be immune to CPU contention causing the test to take significantly longer due to the iteration count.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that. Decided to just keep it simple though. The exact timing isn't important. The cache item should be removed relatively quickly - just not instantly, which is why we check on it in a loop. I'd be shocked if it ever took longer than 1s, but I wanted to be flexible enough so the test isn't noisy. 5s felt like an eternity for this, but in reality, the condition for breaking the loop should be met much, much sooner... and what that exact time is isn't important. Do you think the potential for running so much longer than 5s that it becomes a problem in the test harness is a realistic problem?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh! Also, I switched from I'm going to close this PR and assign the new one for the correct branch to you. It's all the same changes except with one more commit updating to Task.Delay(). |
||
|
|
||
| Assert.Null(mc["key"]); | ||
| } | ||
| finally | ||
| { | ||
| CleanupMonitoring(setup); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.