Xamarin Public Jenkins (auto-signing) 8fc30896db Imported Upstream version 5.12.0.220
Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
2018-04-24 09:31:23 +00:00

69 lines
1.9 KiB
C#

using NUnit.Framework;
using System;
using System.Security.AccessControl;
using System.Threading;
namespace MonoTests.System.Threading {
[TestFixture]
public class WaitHandleTests {
SynchronizationContext OriginalContext;
TestSynchronizationContext TestContext;
[SetUp]
public void SetUp ()
{
OriginalContext = SynchronizationContext.Current;
TestContext = new TestSynchronizationContext();
TestContext.SetWaitNotificationRequired();
SynchronizationContext.SetSynchronizationContext(TestContext);
}
[TearDown]
public void TearDown ()
{
SynchronizationContext.SetSynchronizationContext(OriginalContext);
}
[Test]
#if MONODROID
[Ignore("https://github.com/mono/mono/issues/8349")]
#endif
public void WaitHandle_WaitOne_SynchronizationContext ()
{
var e = new ManualResetEvent(false);
TestContext.WaitAction = () => e.Set();
Assert.IsTrue(e.WaitOne(0));
}
[Test]
public void WaitHandle_WaitAll_SynchronizationContext ()
{
var e1 = new ManualResetEvent(false);
var e2 = new ManualResetEvent(false);
TestContext.WaitAction = () => {
e1.Set();
e2.Set();
};
Assert.IsTrue(WaitHandle.WaitAll(new[] { e1, e2 }, 0));
}
}
class TestSynchronizationContext : SynchronizationContext
{
public Action WaitAction { get; set; }
public new void SetWaitNotificationRequired ()
{
base.SetWaitNotificationRequired();
}
public override int Wait (IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
WaitAction?.Invoke();
return base.Wait(waitHandles, waitAll, millisecondsTimeout);
}
}
}