From 6b0cf66f0e1e2066b2867ccd1a898a4f0a19b716 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 29 Sep 2026 16:50:29 +0200 Subject: [PATCH] Count serializer reads apart in the once-per-landed-record projection test Resolving a variant serializes its base, and the serializer reads the same getters; the test measured them together and expected too few. Co-Authored-By: Claude Sonnet 5 --- .../CultCacheProjectionTests.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/GameCult.Caching.Tests/CultCacheProjectionTests.cs b/tests/GameCult.Caching.Tests/CultCacheProjectionTests.cs index a35db5bd..88f251c6 100644 --- a/tests/GameCult.Caching.Tests/CultCacheProjectionTests.cs +++ b/tests/GameCult.Caching.Tests/CultCacheProjectionTests.cs @@ -189,7 +189,8 @@ namespace GameCult.Caching.Tests [Test] public void EachLandedRecordIsReadOncePerGetterIncludingAVariantDependent() { - using var cache = new CultCache(Registry, CultCacheMessagePack.CreateCodec(Registry)); + var codec = CultCacheMessagePack.CreateCodec(Registry); + using var cache = new CultCache(Registry, codec); var baseKey = new CultRecordKey("projected:base"); Put(cache, new ProjectedRecord { Name = "base", Code = "base-code" }, baseKey); cache.Commit(batch => batch.UpsertVariant(new CultRecordKey("projected:variant"), baseKey, new[] @@ -198,11 +199,16 @@ namespace GameCult.Caching.Tests cache.Override(nameof(ProjectedRecord.Code), "variant-code") })); + // Resolving a variant serializes its base, and the serializer reads the same getters: count those reads apart. + ProjectedRecord.Reads = 0; + codec.Serialize(new ProjectedRecord(), typeof(ProjectedRecord), typeof(ProjectedRecord)); + var serializerReads = Interlocked.Read(ref ProjectedRecord.Reads); + ProjectedRecord.Reads = 0; Put(cache, new ProjectedRecord { Name = "base", Code = "base-code-2" }, baseKey); - // Two landing records (the base, and the variant re-resolved against it), two getters each. - Assert.That(Interlocked.Read(ref ProjectedRecord.Reads), Is.EqualTo(4)); + // Two landing records (the base, and the variant re-resolved against it), two getters each, plus the one serialization. + Assert.That(Interlocked.Read(ref ProjectedRecord.Reads), Is.EqualTo(4 + serializerReads)); Assert.That(cache.GetByIndex("code", "base-code-2"), Is.Not.Null); Assert.That(cache.GetByName("variant"), Is.Not.Null); }