Skip to content

Add guarded LFU LRU integrity checks to soak tests#798

Merged
bitfaster merged 3 commits into
mainfrom
copilot/add-integrity-check-lru-lists
May 2, 2026
Merged

Add guarded LFU LRU integrity checks to soak tests#798
bitfaster merged 3 commits into
mainfrom
copilot/add-integrity-check-lru-lists

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

The LFU soak integrity check did not verify that each internal LRU list's stored count matched its actual contents. This adds count-vs-enumeration validation for the window, protected, and probation lists, with a guard to fail fast if list corruption or enumerator bugs cause non-terminating traversal.

  • What changed

    • Added an enumeration-based integrity assertion for each LFU LRU segment:
      • window
      • protected
      • probation
    • Compared the number of enumerated nodes to the list’s tracked Count.
    • Added an enumeration guard limit so corrupted list links or broken enumeration cannot loop indefinitely during soak validation.
  • Where

    • BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs
    • Extended ConcurrentLfuIntegrityChecker to assert list integrity before existing dictionary/list cross-checks.
  • Failure mode covered

    • Detects mismatched LRU counts.
    • Detects corrupted linked-list traversal that would otherwise over-enumerate or never terminate.
    • Surfaces corruption in the specific segment (window, protected, or probation) with targeted assertion messages.
  • Example

    AssertLruCountMatchesEnumeration(this.windowLru, "window");
    AssertLruCountMatchesEnumeration(this.protectedLru, "protected");
    AssertLruCountMatchesEnumeration(this.probationLru, "probation");
    private void AssertLruCountMatchesEnumeration(LfuNodeList<K, V> lfuNodes, string lruName)
    {
        int enumeratedCount = 0;
        int enumerationGuardLimit = Math.Max(this.cache.Capacity, this.dictionary.Count) + 1;
    
        foreach (var node in lfuNodes)
        {
            enumeratedCount++;
            enumeratedCount.Should().BeLessThanOrEqualTo(
                enumerationGuardLimit,
                $"{lruName} LRU enumeration exceeded the guard limit");
        }
    
        enumeratedCount.Should().Be(lfuNodes.Count, $"{lruName} LRU has a corrupted count");
    }

Copilot AI and others added 3 commits May 1, 2026 18:08
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/56cc9c42-da32-457e-9721-89e01d25f4c4

Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/56cc9c42-da32-457e-9721-89e01d25f4c4

Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 99.136%. remained the same — copilot/add-integrity-check-lru-lists into main

@bitfaster bitfaster marked this pull request as ready for review May 2, 2026 04:20
@bitfaster bitfaster merged commit 6150fe2 into main May 2, 2026
18 checks passed
@bitfaster bitfaster deleted the copilot/add-integrity-check-lru-lists branch May 3, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants