Skip to content

Commit cb13925

Browse files
committed
Merge pull request #772 from flagbug/fix-async-withscheduler
Use an AutoResetEvent instead of a Monitor in TestScheduler.WithScheduler
2 parents 704f43b + 3b27394 commit cb13925

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

ReactiveUI.Testing/TestUtils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ReactiveUI.Testing
1212
{
1313
public static class TestUtils
1414
{
15-
static readonly object schedGate = 42;
15+
static readonly AutoResetEvent schedGate = new AutoResetEvent(true);
1616
static readonly object mbGate = 42;
1717

1818
/// <summary>
@@ -26,7 +26,7 @@ public static class TestUtils
2626
/// schedulers.</returns>
2727
public static IDisposable WithScheduler(IScheduler sched)
2828
{
29-
Monitor.Enter(schedGate);
29+
schedGate.WaitOne();
3030
var prevDef = RxApp.MainThreadScheduler;
3131
var prevTask = RxApp.TaskpoolScheduler;
3232

@@ -36,7 +36,7 @@ public static IDisposable WithScheduler(IScheduler sched)
3636
return Disposable.Create(() => {
3737
RxApp.MainThreadScheduler = prevDef;
3838
RxApp.TaskpoolScheduler = prevTask;
39-
Monitor.Exit(schedGate);
39+
schedGate.Set();
4040
});
4141
}
4242

ReactiveUI.Tests/ReactiveUI.Tests_Net45.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<Compile Include="AwaiterTest.cs" />
104104
<Compile Include="BindingTypeConvertersTest.cs" />
105105
<Compile Include="CommandBindingTests.cs" />
106+
<Compile Include="TestUtilsTest.cs" />
106107
<Compile Include="WeakEventManagerTest.cs" />
107108
<Compile Include="Winforms\ActivationTests.cs" />
108109
<Compile Include="Winforms\CommandBindingTests.cs">

ReactiveUI.Tests/TestUtilsTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.Reactive.Testing;
3+
using ReactiveUI.Testing;
4+
using Xunit;
5+
6+
namespace ReactiveUI.Tests
7+
{
8+
public class TestUtilsTest
9+
{
10+
[Fact]
11+
public async Task WithAsyncScheduler()
12+
{
13+
await new TestScheduler().WithAsync(_ => Task.Run(() => { }));
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)