You've already forked linux-packaging-mono
Imported Upstream version 5.12.0.220
Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
This commit is contained in:
parent
8bd104cef2
commit
8fc30896db
68
mcs/class/System/Test/System.Threading/WaitHandleTests.cs
Normal file
68
mcs/class/System/Test/System.Threading/WaitHandleTests.cs
Normal file
@ -0,0 +1,68 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user