Skip to content

PackageCacheService empty-cache test races process-global cache state #3987

Description

@richlander

Summary

PackageCacheServiceTests.GetCacheInfo_EmptyCache_ReturnsZeroStats can fail in
the Ubuntu CI lane because another parallel test changes and populates the
process-global cache after this test initializes its unique empty cache.

Observed on PR #3810:

Assert.Empty() Failure: Collection was not empty
Collection: [CacheCategoryInfo { Name = pkg-index-v12, Size = 568, Count = 6 }]
at PackageCacheServiceTests.GetCacheInfo_EmptyCache_ReturnsZeroStats()

Evidence

The test calls:

NuGetCache.Initialize("dotnet-inspect-cache-test-empty-" + Guid.NewGuid().ToString("N")[..8]);
var info = PackageCacheService.GetCacheInfo();

but PackageCacheServiceTests is not in CoreCacheCollection. Several other
DotnetInspector.Services.Tests classes that initialize or use CoreCache are
also outside that collection. The xUnit runner executes collections in
parallel, so the unique cache name is not sufficient isolation when another
test can reinitialize the shared static cache between Initialize and
GetCacheInfo.

The failing pkg-index-v12 category belongs to PackageIndexCache, not to the
RTS/product-surface changes in #3810. The same PR head passed the focused local
product, C# shell, RoundTrip, skeleton, authored-corpus, and parity gates.

Expected

Tests that mutate process-global cache initialization should be serialized or
use an instance-scoped test seam so an empty-cache assertion cannot observe
another test's cache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions