From 3fb2613abf603d4b5aac138f074f8ef945fd3ef1 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 29 Sep 2026 23:52:14 +0200 Subject: [PATCH] Networking tests: order is data, so pin each change's own publication, not its delivery order The salvaged S1 and in-place re-upsert tests also asserted the delivery order of the rejected drainer. Under Q-P1 A delivery order across threads and a nested write's depth-first delivery are not guaranteed; each change is published once with its own context, and wire peers drop stale changes by Sequence (Cut 6). Both assertions now say exactly that. The journal tests' reentrant-write recorder subscribes before the handler that writes. Co-Authored-By: Claude Sonnet 5.5 --- tests/GameCult.Networking.Tests/CultNetJournalTests.cs | 2 +- .../CultNetPublicationOrderTests.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/GameCult.Networking.Tests/CultNetJournalTests.cs b/tests/GameCult.Networking.Tests/CultNetJournalTests.cs index c0251af5..d8d0ebd6 100644 --- a/tests/GameCult.Networking.Tests/CultNetJournalTests.cs +++ b/tests/GameCult.Networking.Tests/CultNetJournalTests.cs @@ -303,9 +303,9 @@ namespace GameCult.Networking.Tests var database = Database(cache, primary: true, store); var message = database.Documents.CreateRawDocumentPutMessage( "reentrant-two", new CultRecordHandle(Two), Note("two")); + var published = Record(database); database.Watch().Where(change => change.Key.Equals(One)).Subscribe(_ => database.ApplyPutAsync(message).GetAwaiter().GetResult()); - var published = Record(database); await database.PutAsync(One, Note("one")); diff --git a/tests/GameCult.Networking.Tests/CultNetPublicationOrderTests.cs b/tests/GameCult.Networking.Tests/CultNetPublicationOrderTests.cs index 65e290a4..62d31e69 100644 --- a/tests/GameCult.Networking.Tests/CultNetPublicationOrderTests.cs +++ b/tests/GameCult.Networking.Tests/CultNetPublicationOrderTests.cs @@ -67,7 +67,9 @@ namespace GameCult.Networking.Tests Assert.That(cache.Get(key)!.Text, Is.EqualTo("B"), "the cache admitted A then B"); Assert.That(TextOf(last.Document), Is.EqualTo("B"), "the log's last write for the key must be the cache's last write"); Assert.That(replicaCache.Get(key)?.Text, Is.EqualTo("B"), "a replica built from the log must match the primary"); - Assert.That(seen.Last(), Is.EqualTo("B"), "a subscriber's final state for the key"); + // Delivery is not ordered across threads (order is data: a wire peer drops the stale change by Sequence, Cut 6), + // so a subscriber sees both changes, once each, in either order. + Assert.That(seen, Is.EquivalentTo(new[] { "A", "B" }), "each change is published exactly once"); }); } @@ -336,7 +338,9 @@ namespace GameCult.Networking.Tests await database.PutPredictedAsync(key, Note("predicted")); await database.ApplyPutAsync(message); - Assert.That(seen, Is.EqualTo(new (CultNetDatabaseChangeKind, string?)[] + // The observer's nested write is delivered depth-first, inside the delivery of the change that caused it, so + // the database may publish the two in either order; what is pinned is that each carries its own context. + Assert.That(seen, Is.EquivalentTo(new (CultNetDatabaseChangeKind, string?)[] { (CultNetDatabaseChangeKind.Predicted, null), (CultNetDatabaseChangeKind.Reconciled, "predicted"),