mirror of
https://github.com/ppy/osu.git
synced 2024-11-18 22:52:57 +08:00
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
|
using System;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
using NUnit.Framework;
|
||
|
|
||
|
#nullable enable
|
||
|
|
||
|
namespace osu.Game.Tests.Database
|
||
|
{
|
||
|
[TestFixture]
|
||
|
public class GeneralUsageTests : RealmTest
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Just test the construction of a new database works.
|
||
|
/// </summary>
|
||
|
[Test]
|
||
|
public void TestConstructRealm()
|
||
|
{
|
||
|
RunTestWithRealm((realmFactory, _) => { realmFactory.CreateContext().Refresh(); });
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestBlockOperations()
|
||
|
{
|
||
|
RunTestWithRealm((realmFactory, _) =>
|
||
|
{
|
||
|
using (realmFactory.BlockAllOperations())
|
||
|
{
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestBlockOperationsWithContention()
|
||
|
{
|
||
|
RunTestWithRealm((realmFactory, _) =>
|
||
|
{
|
||
|
ManualResetEventSlim stopThreadedUsage = new ManualResetEventSlim();
|
||
|
ManualResetEventSlim hasThreadedUsage = new ManualResetEventSlim();
|
||
|
|
||
|
Task.Factory.StartNew(() =>
|
||
|
{
|
||
|
using (realmFactory.CreateContext())
|
||
|
{
|
||
|
hasThreadedUsage.Set();
|
||
|
|
||
|
stopThreadedUsage.Wait();
|
||
|
}
|
||
|
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler);
|
||
|
|
||
|
hasThreadedUsage.Wait();
|
||
|
|
||
|
Assert.Throws<TimeoutException>(() =>
|
||
|
{
|
||
|
using (realmFactory.BlockAllOperations())
|
||
|
{
|
||
|
}
|
||
|
});
|
||
|
|
||
|
stopThreadedUsage.Set();
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|