-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug 60568: SynchronizationContext.Wait not implemented or invoked…
… by runtime (#6062) * Checkpoint: Implement SynchronizationContext.Wait * Add missing check for null synchronization context * Update bug 60568 fix to cover WaitAll and add test cases * Add missing file
- Loading branch information
Showing
4 changed files
with
139 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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] | ||
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters