From 791f7e380139b40389cde6d8927e4683dc25607e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 Nov 2021 15:14:27 +0900 Subject: [PATCH] Update `RealmLive` tests in line with modified behaviour --- osu.Game.Tests/Database/RealmLiveTests.cs | 68 ++++++++++++++--------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/osu.Game.Tests/Database/RealmLiveTests.cs b/osu.Game.Tests/Database/RealmLiveTests.cs index f86761fdc8..63566394d6 100644 --- a/osu.Game.Tests/Database/RealmLiveTests.cs +++ b/osu.Game.Tests/Database/RealmLiveTests.cs @@ -66,19 +66,29 @@ namespace osu.Game.Tests.Database Task.Factory.StartNew(() => { - Assert.DoesNotThrow(() => + // TODO: The commented code is the behaviour we hope to obtain, but is temporarily disabled. + // See https://github.com/ppy/osu/pull/15851 + using (realmFactory.CreateContext()) { - using (realmFactory.CreateContext()) + Assert.Throws(() => { - var resolved = liveBeatmap.Value; + var __ = liveBeatmap.Value; + }); + } - Assert.IsTrue(resolved.Realm.IsClosed); - Assert.IsTrue(resolved.IsValid); - - // can access properties without a crash. - Assert.IsFalse(resolved.Hidden); - } - }); + // Assert.DoesNotThrow(() => + // { + // using (realmFactory.CreateContext()) + // { + // var resolved = liveBeatmap.Value; + // + // Assert.IsTrue(resolved.Realm.IsClosed); + // Assert.IsTrue(resolved.IsValid); + // + // // can access properties without a crash. + // Assert.IsFalse(resolved.Hidden); + // } + // }); }, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait(); }); } @@ -199,23 +209,29 @@ namespace osu.Game.Tests.Database Assert.AreEqual(0, updateThreadContext.All().Count()); Assert.AreEqual(0, changesTriggered); - var resolved = liveBeatmap.Value; - - // retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point. - Assert.AreEqual(2, updateThreadContext.All().Count()); - Assert.AreEqual(1, changesTriggered); - - // even though the realm that this instance was resolved for was closed, it's still valid. - Assert.IsTrue(resolved.Realm.IsClosed); - Assert.IsTrue(resolved.IsValid); - - // can access properties without a crash. - Assert.IsFalse(resolved.Hidden); - - updateThreadContext.Write(r => + // TODO: Originally the following was using `liveBeatmap.Value`. This has been temporarily disabled. + // See https://github.com/ppy/osu/pull/15851 + liveBeatmap.PerformRead(resolved => { - // can use with the main context. - r.Remove(resolved); + // retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point. + // ReSharper disable once AccessToDisposedClosure + Assert.AreEqual(2, updateThreadContext.All().Count()); + Assert.AreEqual(1, changesTriggered); + + // TODO: as above, temporarily disabled as it doesn't make sense inside a `PerformRead`. + // // even though the realm that this instance was resolved for was closed, it's still valid. + // Assert.IsTrue(resolved.Realm.IsClosed); + // Assert.IsTrue(resolved.IsValid); + + // can access properties without a crash. + Assert.IsFalse(resolved.Hidden); + + // ReSharper disable once AccessToDisposedClosure + updateThreadContext.Write(r => + { + // can use with the main context. + r.Remove(resolved); + }); }); }