diff options
author | Sebastien Ros <sebastienros@gmail.com> | 2022-09-07 20:56:50 +0300 |
---|---|---|
committer | Sebastien Ros <sebastienros@gmail.com> | 2022-09-07 20:56:50 +0300 |
commit | 309a8de501c711fd1f9d3c9d00c6ccb54251b216 (patch) | |
tree | 0f9fc6e214660b0ee214121a0cb58b69feaf95ac | |
parent | d9880c2dfc5ade8b1ddab734e9cb96ca301726d3 (diff) |
Fix testssebros/cleantags
-rw-r--r-- | src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs | 1 | ||||
-rw-r--r-- | src/Middleware/OutputCaching/test/MemoryOutputCacheStoreTests.cs | 19 |
2 files changed, 9 insertions, 11 deletions
diff --git a/src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs b/src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs index f45db8eb55..e2ab661323 100644 --- a/src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs +++ b/src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs @@ -126,7 +126,6 @@ internal sealed class MemoryOutputCacheStore : IOutputCacheStore if (tagged.Count == 0) { _taggedEntries.Remove(tag); - break; } } } diff --git a/src/Middleware/OutputCaching/test/MemoryOutputCacheStoreTests.cs b/src/Middleware/OutputCaching/test/MemoryOutputCacheStoreTests.cs index c5ec300b6d..5bee23df2c 100644 --- a/src/Middleware/OutputCaching/test/MemoryOutputCacheStoreTests.cs +++ b/src/Middleware/OutputCaching/test/MemoryOutputCacheStoreTests.cs @@ -158,28 +158,27 @@ public class MemoryOutputCacheStoreTests await store.SetAsync("a", value, new[] { "tag1" }, TimeSpan.FromMilliseconds(5), default); await store.SetAsync("b", value, new[] { "tag1", "tag2" }, TimeSpan.FromMilliseconds(5), default); + await store.SetAsync("c", value, new[] { "tag2" }, TimeSpan.FromMilliseconds(20), default); testClock.Advance(TimeSpan.FromMilliseconds(10)); - // Force eviction of expired entries - cache.Compact(0); - - await store.SetAsync("c", value, new[] { "tag2" }, TimeSpan.FromMilliseconds(10), default); + // Background expiration checks are triggered by misc cache activity. + _ = cache.Get("a"); var resulta = await store.GetAsync("a", default); var resultb = await store.GetAsync("b", default); var resultc = await store.GetAsync("c", default); + Assert.Null(resulta); + Assert.Null(resultb); + Assert.NotNull(resultc); + HashSet<string> tag1s, tag2s; // Wait for the hashset to be removed as it happens on a separate thread - var timeout = Task.Delay(1000); + var timeout = Task.Delay(2000); while (store.TaggedEntries.TryGetValue("tag1", out tag1s) && !timeout.IsCompleted) { } - while (store.TaggedEntries.TryGetValue("tag2", out tag2s) && tag2s.Count == 2 && !timeout.IsCompleted) { } - - Assert.Null(resulta); - Assert.Null(resultb); - Assert.NotNull(resultc); + while (store.TaggedEntries.TryGetValue("tag2", out tag2s) && tag2s.Count != 1 && !timeout.IsCompleted) { } Assert.False(timeout.IsCompleted); Assert.Null(tag1s); |