Skip to content

Commit

Permalink
soak lfu rem (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfaster authored Oct 23, 2023
1 parent 393458b commit e783286
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string>().WithCapacity(9).WithScheduler(scheduler).Build() as ConcurrentLfu<int, string>;

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<int, string>().WithCapacity(9).WithScheduler(scheduler).Build() as ConcurrentLfu<int, string>;

await Threaded.Run(4, () => {
for (int i = 0; i < 100000; i++)
{
lfu.TryRemove(new KeyValuePair<int, string>(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);
}

Expand Down

0 comments on commit e783286

Please sign in to comment.