From e6ffe28043305c2a807a9a6aa0a25b6d0fb25dac Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 27 Oct 2026 05:43:02 +0100 Subject: [PATCH] Test: a lossy drift record is refused before the store's lock is asked Kills the staging-flag hand mutant that the apply half's refusal hid. Co-Authored-By: Claude Sonnet 5.5 --- .../GameCult.Caching.Tests/RestampOnWriteTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs b/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs index 12a4fed0..82f473e0 100644 --- a/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs +++ b/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs @@ -181,6 +181,21 @@ namespace GameCult.Caching.Tests Assert.That(Fingerprint(path), Is.EqualTo(before), "a refused write leaves the store as it was"); } + // A held record read only by dropping a slot is refused before anything is staged: with the store's lock held by another + // writer, the write is refused typed instead of waiting on the lock and reporting contention. + [TestCaseSource(nameof(StoreKinds))] + public void ALossyDriftRecordIsRefusedBeforeTheStoresLockIsAsked(bool directory) + { + var path = SeedWide(directory); + using var cache = Open(path, directory, GrownRegistry); + using var held = directory + ? new FileStream(Path.Combine(DirectoryMessagePackBackingStore.DefaultRecordDirectoryPath(path), ".commit.lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None) + : new FileStream(path + ".lock", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); + + Assert.Throws(() => + cache.TryCommit(batch => batch.Upsert(new NoteGrown { Name = "note", Value = 2 }, new CultRecordHandle(Note)))); + } + [TestCaseSource(nameof(StoreKinds))] public void ADeclaredLossyDriftRecordIsWritable(bool directory) {