Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Give up on Thread Locals, synchronize use of overrides

  • Loading branch information...
commit 460fcbd5d456b7eb5da8a7385a013466ff068ee9 1 parent d705835
@paulcbetts paulcbetts authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 ReactiveUI.Testing/TestUtils.cs
View
13 ReactiveUI.Testing/TestUtils.cs
@@ -1,6 +1,7 @@
using System;
using System.Reactive;
using System.Reactive.Disposables;
+using System.Threading;
using Microsoft.Reactive.Testing;
using ReactiveUI;
using System.Reactive.Concurrency;
@@ -9,6 +10,9 @@ namespace ReactiveUI.Testing
{
public static class TestUtils
{
+ static readonly object schedGate = 42;
+ static readonly object mbGate = 42;
+
/// <summary>
/// WithScheduler overrides the default Deferred and Taskpool schedulers
/// with the given scheduler until the return value is disposed. This
@@ -20,6 +24,7 @@ public static class TestUtils
/// schedulers.</returns>
public static IDisposable WithScheduler(IScheduler sched)
{
+ Monitor.Enter(schedGate);
var prevDef = RxApp.DeferredScheduler;
var prevTask = RxApp.TaskpoolScheduler;
@@ -29,6 +34,7 @@ public static IDisposable WithScheduler(IScheduler sched)
return Disposable.Create(() => {
RxApp.DeferredScheduler = prevDef;
RxApp.TaskpoolScheduler = prevTask;
+ Monitor.Exit(schedGate);
});
}
@@ -103,8 +109,13 @@ public static IDisposable WithMessageBus(this TestScheduler sched, IMessageBus m
{
var origMessageBus = RxApp.MessageBus;
+ Monitor.Enter(mbGate);
RxApp.MessageBus = messageBus ?? new MessageBus();
- return Disposable.Create(() => RxApp.MessageBus = origMessageBus);
+ return Disposable.Create(() =>
+ {
+ RxApp.MessageBus = origMessageBus;
+ Monitor.Exit(mbGate);
+ });
}
/// <summary>
Please sign in to comment.
Something went wrong with that request. Please try again.