-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wait for scheduler guards against exception in early initialisat…
…ion (#1312)
- Loading branch information
Showing
6 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
Empty file modified
0
src/ReactiveUI.Tests/Platforms/winforms/CommandBindingTests.cs
100644 → 100755
Empty file.
Empty file modified
0
src/ReactiveUI.Tests/Platforms/winforms/RoutedViewHostTests.cs
100644 → 100755
Empty file.
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,89 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MS-PL license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Reactive.Concurrency; | ||
using System.Reactive.Disposables; | ||
using Xunit; | ||
|
||
namespace ReactiveUI.Tests | ||
{ | ||
public class WaitForDispatcherSchedulerTests | ||
{ | ||
[Fact] | ||
public void CallSchedulerFactoryOnCreation() | ||
{ | ||
var schedulerFactoryCalls = 0; | ||
var schedulerFactory = new Func<IScheduler>(() => { schedulerFactoryCalls++; return null; }); | ||
|
||
var sut = new WaitForDispatcherScheduler(schedulerFactory); | ||
|
||
Assert.Equal(1, schedulerFactoryCalls); | ||
} | ||
|
||
[Fact] | ||
public void FactoryThrowsException_ReCallsOnSchedule() | ||
{ | ||
var schedulerFactoryCalls = 0; | ||
var schedulerFactory = new Func<IScheduler>(() => { | ||
schedulerFactoryCalls++; | ||
throw new InvalidOperationException(); | ||
}); | ||
|
||
var sut = new WaitForDispatcherScheduler(schedulerFactory); | ||
sut.Schedule(() => { }); | ||
|
||
Assert.Equal(2, schedulerFactoryCalls); | ||
} | ||
|
||
[Fact] | ||
public void SuccessfulFactory_UsesCachedScheduler() | ||
{ | ||
var schedulerFactoryCalls = 0; | ||
var schedulerFactory = new Func<IScheduler>(() => { | ||
schedulerFactoryCalls++; | ||
return CurrentThreadScheduler.Instance; | ||
}); | ||
|
||
var sut = new WaitForDispatcherScheduler(schedulerFactory); | ||
sut.Schedule(() => { }); | ||
|
||
Assert.Equal(1, schedulerFactoryCalls); | ||
} | ||
|
||
[Fact] | ||
public void FactoryThrowsInvalidOperationException_FallsBackToCurrentThread() | ||
{ | ||
IScheduler schedulerExecutedOn = null; | ||
var schedulerFactory = new Func<IScheduler>(() => { | ||
throw new InvalidOperationException(); | ||
}); | ||
|
||
var sut = new WaitForDispatcherScheduler(schedulerFactory); | ||
sut.Schedule<object>(null, (scheduler, state) => { | ||
schedulerExecutedOn = scheduler; | ||
return Disposable.Empty; | ||
}); | ||
|
||
Assert.Equal(CurrentThreadScheduler.Instance, schedulerExecutedOn); | ||
} | ||
|
||
[Fact] | ||
public void FactoryThrowsArgumentNullException_FallsBackToCurrentThread() | ||
{ | ||
IScheduler schedulerExecutedOn = null; | ||
var schedulerFactory = new Func<IScheduler>(() => { | ||
throw new ArgumentNullException(); | ||
}); | ||
|
||
var sut = new WaitForDispatcherScheduler(schedulerFactory); | ||
sut.Schedule<object>(null, (scheduler, state) => { | ||
schedulerExecutedOn = scheduler; | ||
return Disposable.Empty; | ||
}); | ||
|
||
Assert.Equal(CurrentThreadScheduler.Instance, schedulerExecutedOn); | ||
} | ||
} | ||
} |
Empty file.
Empty file modified
0
src/ReactiveUI/Platforms/windows-common/ReactiveUserControl.cs
100644 → 100755
Empty file.
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