Skip to content

Commit 8b5e246

Browse files
authored
Verify LRU stability during warmup (#420)
1 parent b027a68 commit 8b5e246

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

BitFaster.Caching.UnitTests/Lru/ConcurrentLruSoakTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using BitFaster.Caching.Lru;
45
using FluentAssertions;
@@ -189,6 +190,26 @@ await Threaded.Run(4, () => {
189190
}
190191
}
191192

193+
[Fact]
194+
public async Task WhenAddingCacheSizeItemsNothingIsEvicted()
195+
{
196+
const int size = 1024;
197+
198+
var cache = new ConcurrentLruBuilder<int, int>()
199+
.WithMetrics()
200+
.WithCapacity(size)
201+
.Build();
202+
203+
await Threaded.Run(4, () =>
204+
{
205+
for (int i = 0; i < size; i++)
206+
{
207+
cache.GetOrAdd(i, k => k);
208+
}
209+
});
210+
211+
cache.Metrics.Value.Evicted.Should().Be(0);
212+
}
192213
private void RunIntegrityCheck()
193214
{
194215
new ConcurrentLruIntegrityChecker<int, string, LruItem<int, string>, LruPolicy<int, string>, TelemetryPolicy<int, string>>(this.lru).Validate();

0 commit comments

Comments
 (0)