diff --git a/tests/GameCult.Caching.Tests/VariantTests.cs b/tests/GameCult.Caching.Tests/VariantTests.cs index f8544e50..2cd7cde2 100644 --- a/tests/GameCult.Caching.Tests/VariantTests.cs +++ b/tests/GameCult.Caching.Tests/VariantTests.cs @@ -90,7 +90,7 @@ namespace GameCult.Caching.Tests Assert.That(big.Tags, Is.EqualTo(new[] { "beam" }), "an inherited list"); Assert.That(cache.Get(BaseKey)!.Power, Is.EqualTo(10)); Assert.That(cache.GetStored(BigKey)!.Variant!.BaseKey, Is.EqualTo(BaseKey.Value)); - Assert.That(cache.GetStored(BigKey)!.Variant!.Overrides, Has.Count.EqualTo(2)); + Assert.That(cache.GetStored(BigKey)!.Variant!.Overrides, Has.Count.EqualTo(3)); } [Test] @@ -442,7 +442,7 @@ namespace GameCult.Caching.Tests Assert.That(reports, Has.Count.EqualTo(2), "one per record: the base and the variant"); Assert.That(reports.Select(report => report.Kind), Is.All.EqualTo(CultSchemaMigrationKind.CompatibleDrift)); Assert.That(reports.Select(report => string.Join(",", report.IgnoredExtraSlots)), Is.All.EqualTo("2")); - Assert.That(reports.SelectMany(report => report.Warnings).Select(warning => warning.Code), Is.All.EqualTo("ignored_extra_slot")); + Assert.That(reports.Select(report => report.Warnings.Select(warning => warning.Code)), Has.All.Contain("ignored_extra_slot")); } private static readonly byte[] NotAnInt = { 0xa3, (byte)'a', (byte)'b', (byte)'c' }; @@ -582,7 +582,7 @@ namespace GameCult.Caching.Tests [Test] public void ALoadedVariantThatInheritsAnIndexedValueRefusesTheLoadNamingBothKeys() { - var path = WriteStore(PlainGear("hand-base"), OverridingRecord("hand-variant", "hand-base")); + var path = WriteStore(PlainGear("hand-base"), OverridingRecord("hand-variant", "hand-base", TextOverride(0, "hand variant"))); var refused = Assert.Throws(() => Open(path).Dispose())!; Assert.That(refused.Message, Does.Contain("hand-variant").And.Contain("hand-base").And.Contain("code")); } @@ -843,7 +843,7 @@ namespace GameCult.Caching.Tests SeedBase(cache); var push = Assert.Throws(() => cache.UpsertVariantAsync( - BigKey, BaseKey, new[] { cache.Override(nameof(VariantGear.Name), "laser big") }).GetAwaiter().GetResult())!; + BigKey, BaseKey, new[] { cache.Override(nameof(VariantGear.Name), "laser big"), cache.Override(nameof(VariantGear.Code), "laser big") }).GetAwaiter().GetResult())!; Assert.That(push.Message, Does.Contain(BigKey.Value)); var commit = Assert.Throws(() => SeedBig(cache))!; Assert.That(commit.Message, Does.Contain(BigKey.Value)); diff --git a/tests/GameCult.Networking.Tests/CultNetDocumentRegistryVariantTests.cs b/tests/GameCult.Networking.Tests/CultNetDocumentRegistryVariantTests.cs index 2a8ddc58..8c70c31e 100644 --- a/tests/GameCult.Networking.Tests/CultNetDocumentRegistryVariantTests.cs +++ b/tests/GameCult.Networking.Tests/CultNetDocumentRegistryVariantTests.cs @@ -83,11 +83,11 @@ namespace GameCult.Networking.Tests using (var writer = CultCacheMessagePack.Create(path, new CultCacheOpenOptions { Registry = registry })) { writer.Commit(batch => batch.Upsert(typeof(VariantWireFixture), new VariantWireFixture { Name = "base", Power = 1 }, BaseKey)); - writer.UpsertVariantAsync(VariantKey, BaseKey, new[] + writer.Commit(batch => batch.UpsertVariant(VariantKey, BaseKey, new[] { writer.Override(nameof(VariantWireFixture.Name), "big"), writer.Override(nameof(VariantWireFixture.Power), 9) - }).GetAwaiter().GetResult(); + })); } var cache = new CultCache(registry, CultCacheMessagePack.CreateCodec(registry)); @@ -128,13 +128,15 @@ namespace GameCult.Networking.Tests { MessageId = "subscribe-all", SubscriptionId = "all", + RecordKeys = new[] { BaseKey.Value, VariantKey.Value }, IncludeSnapshot = true }); await WaitUntilAsync(() => snapshot.Task.IsCompleted); cache.AddBackingStore(new SingleFileMessagePackBackingStore(path)); - await WaitUntilAsync(() => !errors.IsEmpty || changes.Any(change => change.Document?.RecordKey == VariantKey.Value)); + await WaitUntilAsync(() => !errors.IsEmpty || changes.Any(change => change.Document?.RecordKey == VariantKey.Value), + () => $"changes={string.Join(",", changes.Select(c => c.ChangeKind + ":" + c.Document?.RecordKey))} errors={string.Join(",", errors.Select(e => e.Error))} cacheKeys={cache.GetStored(BaseKey) != null}/{cache.GetStored(VariantKey) != null}"); await Task.Delay(200); // let anything else already in flight arrive Assert.That(changes.Select(change => change.Document?.RecordKey), Does.Not.Contain(VariantKey.Value), @@ -180,13 +182,13 @@ namespace GameCult.Networking.Tests Assert.That(refused.InnerException!.Message, Does.Contain(VariantKey.Value).And.Contain(BaseKey.Value)); } - private static async Task WaitUntilAsync(Func condition) + private static async Task WaitUntilAsync(Func condition, Func? diagnostic = null) { var deadline = DateTimeOffset.UtcNow + TimeSpan.FromSeconds(5); while (!condition()) { if (DateTimeOffset.UtcNow > deadline) - Assert.Fail("Condition was not satisfied before timeout."); + Assert.Fail("Condition was not satisfied before timeout. " + diagnostic?.Invoke()); await Task.Delay(5); } }