From af7751e26395fd007e7df4f1bb08a0f167227333 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 00:24:40 +0200 Subject: [PATCH] Journal tests: the nested shard-log apply must finish, and the store-writes-cache probe fires once The reentrant apply test now asserts the nested call completes without throwing: a re-recorded sequence used to be swallowed by the subscriber's handler and hide a non-replacing in-memory log. The store-writes-cache probe writes once, so a cache that let the journal re-enter it fails the test instead of recursing until the host crashes. Co-Authored-By: Claude Sonnet 5.5 --- .../CultNetJournalTests.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/GameCult.Networking.Tests/CultNetJournalTests.cs b/tests/GameCult.Networking.Tests/CultNetJournalTests.cs index d8d0ebd6..25d9b5cf 100644 --- a/tests/GameCult.Networking.Tests/CultNetJournalTests.cs +++ b/tests/GameCult.Networking.Tests/CultNetJournalTests.cs @@ -280,16 +280,27 @@ namespace GameCult.Networking.Tests var replicaCache = new CultCache(); var replica = Database(replicaCache, primary: false, replicaStore); var nested = false; + long nestedApplied = 0; + Exception? nestedFailure = null; replica.Watch().Where(change => change.Key.Equals(One)).Subscribe(_ => { if (nested) return; nested = true; - replica.ApplyShardLogResponseAsync(response).GetAwaiter().GetResult(); + try + { + nestedApplied = replica.ApplyShardLogResponseAsync(response).GetAwaiter().GetResult(); + } + catch (Exception exception) + { + nestedFailure = exception; + } }); await replica.ApplyShardLogResponseAsync(response); Assert.That(nested, Is.True); + Assert.That(nestedFailure, Is.Null, "the nested apply re-records entries the outer apply already logged"); + Assert.That(nestedApplied, Is.EqualTo(3)); Assert.That(replica.GetMutationLog(ShardId).Select(entry => entry.Sequence), Is.EqualTo(new[] { 1L, 2L, 3L })); Assert.That(Sequences(replicaStore), Is.EqualTo(new[] { 1L, 2L, 3L })); Assert.That(replica.GetAppliedShardSequence(ShardId), Is.EqualTo(3)); @@ -319,7 +330,12 @@ namespace GameCult.Networking.Tests public async Task ALogStoreThatWritesTheCacheFailsThroughTheReentryGuardAndTheAdmissionStands() { var cache = new CultCache(); - var store = new FlakyLogStore { OnAppend = () => cache.UpsertAsync(Note("from the store"), new CultRecordHandle(Three)).GetAwaiter().GetResult() }; + var store = new FlakyLogStore(); + store.OnAppend = () => + { + store.OnAppend = null; + cache.UpsertAsync(Note("from the store"), new CultRecordHandle(Three)).GetAwaiter().GetResult(); + }; var database = Database(cache, primary: true, store); var published = Record(database);