Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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