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
22 changes: 19 additions & 3 deletions BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BitFaster.Caching.Lfu;
using BitFaster.Caching.Scheduler;
using FluentAssertions;
using FluentAssertions.Equivalency;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -495,9 +496,11 @@ private async Task RunIntegrityCheckAsync(ConcurrentLfu<string, string> lfu, int
{
this.output.WriteLine($"iteration {iteration} keys={string.Join(" ", lfu.Keys)}");

var scheduler = lfu.Scheduler as BackgroundThreadScheduler;
scheduler.Dispose();
await scheduler.Completion;
if (lfu.Scheduler is BackgroundThreadScheduler scheduler)
{
scheduler.Dispose();
await scheduler.Completion;
}

RunIntegrityCheck(lfu, this.output);
}
Expand Down Expand Up @@ -545,6 +548,12 @@ public void Validate(ITestOutputHelper output)
{
cache.DoMaintenance();

if (cache.Scheduler.LastException.HasValue)
{
output.WriteLine($"Last scheduler exception {cache.Scheduler.LastException.Value}");
cache.Scheduler.LastException.Should().BeNull("scheduler should not have thrown");
}

// buffers should be empty after maintenance
this.readBuffer.Count.Should().Be(0);
this.writeBuffer.Count.Should().Be(0);
Expand All @@ -571,6 +580,13 @@ private void VerifyLruInDictionary(LfuNodeList<K, V> lfuNodes, ITestOutputHelper
node.WasRemoved.Should().BeFalse();
node.WasDeleted.Should().BeFalse();

// additional diagnbostics
if (!cache.TryGet(node.Key, out _))
{
output.WriteLine($"Orphaned node at {node.Position} with key {node.Key} and value {node.Value}.");
output.WriteLine($"Read buffer {cache.readBuffer.Count} write buffer {cache.writeBuffer.Count}.");
}

cache.TryGet(node.Key, out _).Should().BeTrue($"Orphaned node with key {node.Key} detected.");

node = node.Next;
Expand Down
Loading