Skip to content

fix(test): replace flaky cache consistency assertion with independent invariants#42

Merged
hooyao merged 2 commits into
mainfrom
fix/flaky-cache-consistency-test
Apr 2, 2026
Merged

fix(test): replace flaky cache consistency assertion with independent invariants#42
hooyao merged 2 commits into
mainfrom
fix/flaky-cache-consistency-test

Conversation

@hooyao
Copy link
Copy Markdown
Owner

@hooyao hooyao commented Apr 2, 2026

Summary

  • ConcurrentOperationsWithEviction test was intermittently failing in CI due to a non-atomic read of EntryCount and CurrentSizeBytes followed by an exact equality assertion
  • Replace with four independent invariant checks that don't require an atomic cross-property snapshot:
    • CurrentSizeBytes >= 0 (never negative)
    • CurrentSizeBytes <= capacity (never exceeds limit)
    • CurrentSizeBytes % entrySize == 0 (no partial entry size leaks)
    • EntryCount == 0 implies CurrentSizeBytes == 0 (empty cache has zero size)

Test plan

  • Fixed test passes 10/10 consecutive runs locally
  • Full test suite passes

🤖 Generated with Claude Code

…variants

The ConcurrentOperationsWithEviction test read EntryCount and
CurrentSizeBytes in two non-atomic steps, then asserted exact equality.
Under concurrent eviction, these properties can be observed at different
points in time, causing intermittent failures.

Replace with independent invariant checks: size >= 0, size <= capacity,
size is a multiple of entry size (no partial leaks), and size == 0 when
entry count is 0.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 2, 2026 08:50
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

Test Results

Suite Passed Failed Skipped Total
✅ Domain 113 0 0 113
✅ Infrastructure.Archives.Zip 54 0 0 54
✅ Infrastructure.Caching 169 0 0 169
✅ IntegrationTests 74 0 0 74
Total 410 0 0 410

Summary

Summary
Generated on: 4/2/2026 - 8:59:54 AM
Coverage date: 4/2/2026 - 8:59:24 AM - 4/2/2026 - 8:59:48 AM
Parser: MultiReport (8x Cobertura)
Assemblies: 8
Classes: 99
Files: 83
Line coverage: 56.5% (2565 of 4539)
Covered lines: 2565
Uncovered lines: 1974
Coverable lines: 4539
Total lines: 10814
Branch coverage: 54.4% (794 of 1458)
Covered branches: 794
Total branches: 1458
Method coverage: Feature is only available for sponsors

Coverage

ZipDrive - 2%
Name Line Branch
ZipDrive 2% 18.1%
Program 0% 0%
ZipDrive.Cli.ArgPreprocessor 100% 100%
ZipDrive.Application - 85.4%
Name Line Branch
ZipDrive.Application 85.4% 76.2%
ZipDrive.Application.Services.ArchiveDiscovery 80.5% 87.5%
ZipDrive.Application.Services.ArchiveGuard 85.7% 50%
ZipDrive.Application.Services.ArchiveNode 83.7% 72.2%
ZipDrive.Application.Services.ArchivePathHelper 100%
ZipDrive.Application.Services.ArchiveTrie 100% 95.4%
ZipDrive.Application.Services.ArchiveVirtualFileSystem 83.4% 69.4%
ZipDrive.Application.Services.FormatRegistry 100% 92.8%
ZipDrive.Application.Services.PathResolver 100% 100%
ZipDrive.Application.Services.PrefetchTelemetry 0%
ZipDrive.Domain - 45.5%
Name Line Branch
ZipDrive.Domain 45.5% 43.1%
ZipDrive.Domain.Abstractions.IArchiveStructureBuilder 100%
ZipDrive.Domain.CaseInsensitiveCharComparer 75%
ZipDrive.Domain.Configuration.MountSettings 88.8%
ZipDrive.Domain.Configuration.PrefetchOptions 100%
ZipDrive.Domain.Exceptions.ArchiveNotFoundException 0%
ZipDrive.Domain.Exceptions.CorruptZipException 42.8%
ZipDrive.Domain.Exceptions.EncryptedEntryException 0%
ZipDrive.Domain.Exceptions.EntryCountMismatchException 0%
ZipDrive.Domain.Exceptions.EocdNotFoundException 100%
ZipDrive.Domain.Exceptions.InvalidArchiveException 0%
ZipDrive.Domain.Exceptions.InvalidOffsetException 0%
ZipDrive.Domain.Exceptions.InvalidSignatureException 0%
ZipDrive.Domain.Exceptions.MultiDiskArchiveException 0%
ZipDrive.Domain.Exceptions.PathResolutionException 0%
ZipDrive.Domain.Exceptions.UnsupportedCompressionException 0% 0%
ZipDrive.Domain.Exceptions.VfsAccessDeniedException 75%
ZipDrive.Domain.Exceptions.VfsDirectoryNotFoundException 75%
ZipDrive.Domain.Exceptions.VfsException 50%
ZipDrive.Domain.Exceptions.VfsFileNotFoundException 42.8%
ZipDrive.Domain.Exceptions.Zip64RequiredException 0%
ZipDrive.Domain.Exceptions.ZipException 42.8%
ZipDrive.Domain.Models.ArchiveCapabilities 0%
ZipDrive.Domain.Models.ArchiveDescriptor 100% 100%
ZipDrive.Domain.Models.ArchiveEntry 0%
ZipDrive.Domain.Models.ArchiveEntryInfo 100%
ZipDrive.Domain.Models.ArchiveInfo 0%
ZipDrive.Domain.Models.ArchiveProbeResult 100%
ZipDrive.Domain.Models.ArchivesChangedEventArgs 0%
ZipDrive.Domain.Models.ArchiveStructure 100% 85%
ZipDrive.Domain.Models.ArchiveTrieResult 100%
ZipDrive.Domain.Models.DirectorySynthesizer 0% 0%
ZipDrive.Domain.Models.ExtractionResult 100%
ZipDrive.Domain.Models.MountOptions 0%
ZipDrive.Domain.Models.PathResolutionResult 0%
ZipDrive.Domain.Models.VfsFileInfo 100%
ZipDrive.Domain.Models.VfsMountOptions 100%
ZipDrive.Domain.Models.VfsVolumeInfo 100%
ZipDrive.Domain.Models.VirtualFolderEntry 100%
ZipDrive.Infrastructure.Archives.Rar - 0%
Name Line Branch
ZipDrive.Infrastructure.Archives.Rar 0% 0%
ZipDrive.Infrastructure.Archives.Rar.RarEntryExtractor 0% 0%
ZipDrive.Infrastructure.Archives.Rar.RarSignature 0% 0%
ZipDrive.Infrastructure.Archives.Rar.RarStructureBuilder 0% 0%
ZipDrive.Infrastructure.Archives.Zip - 72.5%
Name Line Branch
ZipDrive.Infrastructure.Archives.Zip 72.5% 62.2%
ZipDrive.Infrastructure.Archives.Zip.FilenameEncodingDetector 69.4% 77.7%
ZipDrive.Infrastructure.Archives.Zip.Formats.ZipCentralDirectoryEntry 91.8% 68.1%
ZipDrive.Infrastructure.Archives.Zip.Formats.ZipEocd 100%
ZipDrive.Infrastructure.Archives.Zip.Formats.ZipLocalHeader 80%
ZipDrive.Infrastructure.Archives.Zip.SpanSelector 92.9% 75%
ZipDrive.Infrastructure.Archives.Zip.SubStream 39% 37.5%
ZipDrive.Infrastructure.Archives.Zip.ZipEntryExtractor 85.7%
ZipDrive.Infrastructure.Archives.Zip.ZipEntryInfo 75% 0%
ZipDrive.Infrastructure.Archives.Zip.ZipFormatMetadataStore 100% 100%
ZipDrive.Infrastructure.Archives.Zip.ZipPrefetchPlan 100%
ZipDrive.Infrastructure.Archives.Zip.ZipPrefetchStrategy 82.7% 73.6%
ZipDrive.Infrastructure.Archives.Zip.ZipReader 59% 45.5%
ZipDrive.Infrastructure.Archives.Zip.ZipReaderFactory 100% 50%
ZipDrive.Infrastructure.Archives.Zip.ZipStructureBuilder 95.3% 86%
ZipDrive.Infrastructure.Archives.Zip.ZipTelemetry 100%
ZipDrive.Infrastructure.Caching - 78.3%
Name Line Branch
ZipDrive.Infrastructure.Caching 78.3% 72.6%
ZipDrive.Infrastructure.Caching.ArchiveStructureCache 76.3% 20%
ZipDrive.Infrastructure.Caching.ArchiveStructureStore 72.7%
ZipDrive.Infrastructure.Caching.CacheEntry 100% 50%
ZipDrive.Infrastructure.Caching.CacheFactoryResult`1 100% 100%
ZipDrive.Infrastructure.Caching.CacheHandle`1 100% 75%
ZipDrive.Infrastructure.Caching.CacheMaintenanceService 0% 0%
ZipDrive.Infrastructure.Caching.CacheOptions 66.6% 50%
ZipDrive.Infrastructure.Caching.CacheTelemetry 52.7% 14.2%
ZipDrive.Infrastructure.Caching.ChunkedDiskStorageStrategy 70.9% 52.6%
ZipDrive.Infrastructure.Caching.ChunkedFileEntry 86.3% 84.7%
ZipDrive.Infrastructure.Caching.ChunkedStream 83.3% 79.1%
ZipDrive.Infrastructure.Caching.FileContentCache 90.6% 84.3%
ZipDrive.Infrastructure.Caching.GenericCache`1 83.5% 78.7%
ZipDrive.Infrastructure.Caching.LruEvictionPolicy 100% 100%
ZipDrive.Infrastructure.Caching.MemoryStorageStrategy 85.7% 75%
ZipDrive.Infrastructure.Caching.ObjectStorageStrategy`1 90.9% 75%
ZipDrive.Infrastructure.Caching.SizeBucketClassifier 100% 100%
ZipDrive.Infrastructure.Caching.StoredEntry 100%
ZipDrive.Infrastructure.FileSystem - 4.6%
Name Line Branch
ZipDrive.Infrastructure.FileSystem 4.6% 8.5%
ZipDrive.Infrastructure.FileSystem.ArchiveChangeConsolidator 0% 0%
ZipDrive.Infrastructure.FileSystem.ArchiveChangeDelta 0%
ZipDrive.Infrastructure.FileSystem.DokanFileSystemAdapter 0% 0%
ZipDrive.Infrastructure.FileSystem.DokanHostedService 0% 0%
ZipDrive.Infrastructure.FileSystem.DokanTelemetry 0%
ZipDrive.Infrastructure.FileSystem.ShellMetadataFilter 100% 93.7%
ZipDrive.Infrastructure.FileSystem.UserNotice 0%
ZipDrive.TestHelpers - 40.5%
Name Line Branch
ZipDrive.TestHelpers 40.5% 28.4%
ZipDrive.TestHelpers.ManifestEntry 100%
ZipDrive.TestHelpers.NullHostApplicationLifetime 25%
ZipDrive.TestHelpers.PartialSample 100%
ZipDrive.TestHelpers.TestRarGenerator 0% 0%
ZipDrive.TestHelpers.TestZipGenerator 54% 37.3%
ZipDrive.TestHelpers.VfsTestFixture 98% 100%
ZipDrive.TestHelpers.ZipManifest 100%

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates a flaky concurrency integration test in the caching subsystem by replacing an exact cross-property equality assertion with a set of invariant-based assertions that are intended to remain valid without requiring an atomic snapshot of multiple cache metrics.

Changes:

  • Replaced CurrentSizeBytes == EntryCount * entrySize with invariant checks on CurrentSizeBytes.
  • Added assertions for non-negativity, capacity upper bound, and size alignment to entry size.
  • Added a conditional empty-cache consistency assertion (EntryCount == 0 implies CurrentSizeBytes == 0).

Comment thread tests/ZipDrive.Infrastructure.Caching.Tests/GenericCacheIntegrationTests.cs Outdated
Comment thread tests/ZipDrive.Infrastructure.Caching.Tests/GenericCacheIntegrationTests.cs Outdated
- Cast entrySize * cacheCapacity to long to prevent int overflow
- Remove entryCount == 0 → size == 0 assertion (still cross-property)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hooyao hooyao merged commit 0af681e into main Apr 2, 2026
5 checks passed
@hooyao hooyao deleted the fix/flaky-cache-consistency-test branch April 2, 2026 10:16
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.

2 participants