mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:42:56 +08:00
Add test coverage of potential deeadlock scenario with nested realm context fetching
This commit is contained in:
parent
448b2d1190
commit
54798eabc9
@ -5,6 +5,9 @@ using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Models;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
|
||||
@ -33,6 +36,37 @@ namespace osu.Game.Tests.Database
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNestedContextCreation()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
{
|
||||
var mainContext = realmFactory.Context;
|
||||
bool callbackRan = false;
|
||||
|
||||
var subscription = mainContext.All<RealmBeatmap>().SubscribeForNotifications((sender, changes, error) =>
|
||||
{
|
||||
realmFactory.CreateContext();
|
||||
callbackRan = true;
|
||||
});
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBlockOperationsWithContention()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user