From e783286c0c4ff499eaca6c093c6901e10f344926 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Mon, 23 Oct 2023 01:12:41 -0700 Subject: [PATCH] soak lfu rem (#439) --- .../Lfu/ConcurrentLfuSoakTests.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs index 7f84e9d2..b620ed58 100644 --- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs @@ -131,6 +131,52 @@ await Threaded.Run(4, () => { scheduler.Dispose(); await scheduler.Completion; + RunIntegrityCheck(lfu); + } + + [Theory] + [Repeat(iterations)] + public async Task WhenSoakConcurrentGetAndRemoveCacheEndsInConsistentState(int iteration) + { + var scheduler = new BackgroundThreadScheduler(); + var lfu = new ConcurrentLfuBuilder().WithCapacity(9).WithScheduler(scheduler).Build() as ConcurrentLfu; + + await Threaded.Run(4, () => { + for (int i = 0; i < 100000; i++) + { + lfu.TryRemove(i + 1); + lfu.GetOrAdd(i + 1, i => i.ToString()); + } + }); + + this.output.WriteLine($"iteration {iteration} keys={string.Join(" ", lfu.Keys)}"); + + scheduler.Dispose(); + await scheduler.Completion; + + RunIntegrityCheck(lfu); + } + + [Theory] + [Repeat(iterations)] + public async Task WhenConcurrentGetAndRemoveKvpCacheEndsInConsistentState(int iteration) + { + var scheduler = new BackgroundThreadScheduler(); + var lfu = new ConcurrentLfuBuilder().WithCapacity(9).WithScheduler(scheduler).Build() as ConcurrentLfu; + + await Threaded.Run(4, () => { + for (int i = 0; i < 100000; i++) + { + lfu.TryRemove(new KeyValuePair(i + 1, (i + 1).ToString())); + lfu.GetOrAdd(i + 1, i => i.ToString()); + } + }); + + this.output.WriteLine($"iteration {iteration} keys={string.Join(" ", lfu.Keys)}"); + + scheduler.Dispose(); + await scheduler.Completion; + RunIntegrityCheck(lfu); }