Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ await Threaded.RunAsync(4, async () => {
scheduler.Dispose();
await scheduler.Completion;

RunIntegrityCheck(lfu);
}

[Theory]
[Repeat(iterations)]
public async Task WhenConcurrentGetAndUpdateCacheEndsInConsistentState(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.TryUpdate(i + 1, i.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
8 changes: 7 additions & 1 deletion BitFaster.Caching/Lfu/ConcurrentLfu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,13 @@ private void OnWrite(LfuNode<K, V> node)
}

private void PromoteProbation(LfuNode<K, V> node)
{
{
if (node.list == null)
{
// Ignore stale accesses for an entry that is no longer present
return;
}

this.probationLru.Remove(node);
this.protectedLru.AddLast(node);
node.Position = Position.Protected;
Expand Down