mirror of
https://github.com/ppy/osu
synced 2025-01-15 18:41:14 +00:00
Refactor test to be easier to follow
This commit is contained in:
parent
0bcfb8e199
commit
566e10f8cc
@ -36,34 +36,36 @@ namespace osu.Game.Tests.Database
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test to ensure that a `CreateContext` call nested inside a subscription doesn't cause any deadlocks
|
||||||
|
/// due to context fetching semaphores.
|
||||||
|
/// </summary>
|
||||||
[Test]
|
[Test]
|
||||||
public void TestNestedContextCreation()
|
public void TestNestedContextCreationWithSubscription()
|
||||||
{
|
{
|
||||||
RunTestWithRealm((realmFactory, _) =>
|
RunTestWithRealm((realmFactory, _) =>
|
||||||
{
|
{
|
||||||
var mainContext = realmFactory.Context;
|
|
||||||
bool callbackRan = false;
|
bool callbackRan = false;
|
||||||
|
|
||||||
var subscription = mainContext.All<RealmBeatmap>().SubscribeForNotifications((sender, changes, error) =>
|
using (var context = realmFactory.CreateContext())
|
||||||
|
{
|
||||||
|
var subscription = context.All<RealmBeatmap>().SubscribeForNotifications((sender, changes, error) =>
|
||||||
|
{
|
||||||
|
using (realmFactory.CreateContext())
|
||||||
{
|
{
|
||||||
realmFactory.CreateContext();
|
|
||||||
callbackRan = true;
|
callbackRan = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
// Force the callback above to run.
|
||||||
|
using (realmFactory.CreateContext())
|
||||||
{
|
{
|
||||||
using (var threadContext = realmFactory.CreateContext())
|
|
||||||
{
|
|
||||||
threadContext.Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata())));
|
|
||||||
}
|
}
|
||||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).Wait();
|
|
||||||
|
|
||||||
// will create a context but also run the callback above (Refresh is implicitly run when getting a new context).
|
|
||||||
realmFactory.CreateContext();
|
|
||||||
|
|
||||||
Assert.IsTrue(callbackRan);
|
|
||||||
|
|
||||||
subscription.Dispose();
|
subscription.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsTrue(callbackRan);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user