mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 23:53:51 +09:00
Update tests to match new behaviour
This commit is contained in:
@ -46,53 +46,6 @@ namespace osu.Game.Tests.Database
|
|||||||
Assert.IsFalse(liveBeatmap.PerformRead(l => l.Hidden));
|
Assert.IsFalse(liveBeatmap.PerformRead(l => l.Hidden));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestValueAccessWithOpenContext()
|
|
||||||
{
|
|
||||||
RunTestWithRealm((realmFactory, _) =>
|
|
||||||
{
|
|
||||||
RealmLive<RealmBeatmap>? liveBeatmap = null;
|
|
||||||
Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
using (var threadContext = realmFactory.CreateContext())
|
|
||||||
{
|
|
||||||
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
|
||||||
|
|
||||||
liveBeatmap = beatmap.ToLive();
|
|
||||||
}
|
|
||||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
|
||||||
|
|
||||||
Debug.Assert(liveBeatmap != null);
|
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
// 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())
|
|
||||||
{
|
|
||||||
Assert.Throws<InvalidOperationException>(() =>
|
|
||||||
{
|
|
||||||
var __ = liveBeatmap.Value;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestScopedReadWithoutContext()
|
public void TestScopedReadWithoutContext()
|
||||||
{
|
{
|
||||||
@ -148,6 +101,59 @@ namespace osu.Game.Tests.Database
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestValueAccessNonManaged()
|
||||||
|
{
|
||||||
|
RunTestWithRealm((realmFactory, _) =>
|
||||||
|
{
|
||||||
|
var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata());
|
||||||
|
var liveBeatmap = beatmap.ToLive();
|
||||||
|
|
||||||
|
Assert.DoesNotThrow(() =>
|
||||||
|
{
|
||||||
|
var __ = liveBeatmap.Value;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestValueAccessWithOpenContextFails()
|
||||||
|
{
|
||||||
|
RunTestWithRealm((realmFactory, _) =>
|
||||||
|
{
|
||||||
|
RealmLive<RealmBeatmap>? liveBeatmap = null;
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
using (var threadContext = realmFactory.CreateContext())
|
||||||
|
{
|
||||||
|
var beatmap = threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
||||||
|
|
||||||
|
liveBeatmap = beatmap.ToLive();
|
||||||
|
}
|
||||||
|
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||||
|
|
||||||
|
Debug.Assert(liveBeatmap != null);
|
||||||
|
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
// Can't be used, without a valid context.
|
||||||
|
Assert.Throws<InvalidOperationException>(() =>
|
||||||
|
{
|
||||||
|
var __ = liveBeatmap.Value;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Can't be used, even from within a valid context.
|
||||||
|
using (realmFactory.CreateContext())
|
||||||
|
{
|
||||||
|
Assert.Throws<InvalidOperationException>(() =>
|
||||||
|
{
|
||||||
|
var __ = liveBeatmap.Value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestValueAccessWithoutOpenContextFails()
|
public void TestValueAccessWithoutOpenContextFails()
|
||||||
{
|
{
|
||||||
@ -209,8 +215,6 @@ namespace osu.Game.Tests.Database
|
|||||||
Assert.AreEqual(0, updateThreadContext.All<RealmBeatmap>().Count());
|
Assert.AreEqual(0, updateThreadContext.All<RealmBeatmap>().Count());
|
||||||
Assert.AreEqual(0, changesTriggered);
|
Assert.AreEqual(0, changesTriggered);
|
||||||
|
|
||||||
// TODO: Originally the following was using `liveBeatmap.Value`. This has been temporarily disabled.
|
|
||||||
// See https://github.com/ppy/osu/pull/15851
|
|
||||||
liveBeatmap.PerformRead(resolved =>
|
liveBeatmap.PerformRead(resolved =>
|
||||||
{
|
{
|
||||||
// retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point.
|
// retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point.
|
||||||
@ -218,11 +222,6 @@ namespace osu.Game.Tests.Database
|
|||||||
Assert.AreEqual(2, updateThreadContext.All<RealmBeatmap>().Count());
|
Assert.AreEqual(2, updateThreadContext.All<RealmBeatmap>().Count());
|
||||||
Assert.AreEqual(1, changesTriggered);
|
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.
|
// can access properties without a crash.
|
||||||
Assert.IsFalse(resolved.Hidden);
|
Assert.IsFalse(resolved.Hidden);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user