public void MappedAsyncObservablesMaintainAsynchronicity() { var observable = CreateIntAsyncEnumerable().CreateAsyncObservable().Select(v => (double)v); var observer = new TestUtils.TestObserver <double>(StreamLength, SequenceMillisDelay, DelayTolerance); using (observable.Subscribe(observer)) observer.WaitForCompletion(); // WaitForCompletion will do tests... }
public void ObservationsFromAsyncObservableAreOnTheTaskPoolSchedulerByDefault() { var observable = CreateIntAsyncEnumerable().CreateAsyncObservable(); var observer = new TestUtils.TestObserver <int>(); using (observable.Subscribe(observer)) observer.WaitForCompletion(); observer.NotificationThreadIds.Should().NotContain(Thread.CurrentThread.ManagedThreadId, "Unexpectedly notified on main thread"); observer.NotificationTaskIds.Should().HaveCountGreaterOrEqualTo(1); observer.NotificationTaskIds.Should().NotContainNulls("Notifications were not using the Task pool"); }
public void ObservationsFromAsyncObservableAreOnTheTaskPoolSchedulerByDefault() { var observable = CreateIntAsyncEnumerable().CreateAsyncObservable(); var observer = new TestUtils.TestObserver <int>(); using (observable.Subscribe(observer)) observer.WaitForCompletion(); Assert.IsFalse(observer.NotificationThreadIds.Contains(Thread.CurrentThread.ManagedThreadId), "Unexpectedly notified on main thread"); Assert.IsTrue(observer.NotificationTaskIds.Count >= 1); Assert.IsFalse(observer.NotificationTaskIds.Contains(null), "Notifications were not using the Task pool"); }
public void SubscriptionToAsyncObservableDoesNotBlockByDefault() { var observable = CreateIntAsyncEnumerable().CreateAsyncObservable(); var observer = new TestUtils.TestObserver <int>(); DateTime before = DateTime.UtcNow; DateTime after; using (observable.Subscribe(observer)) { after = DateTime.UtcNow; observer.WaitForCompletion(); } int delay = (int)(after - before).TotalMilliseconds; delay.Should().BeInRange(0, DelayTolerance, "Subscribe method blocked"); }
private void CheckNotificationsOnMainThread(IObservable <int> observable) { var observer = new TestUtils.TestObserver <int>(); DateTime before = DateTime.UtcNow; DateTime after; using (observable.Subscribe(observer)) { after = DateTime.UtcNow; observer.WaitForCompletion(); } int delay = (int)(after - before).TotalMilliseconds; Assert.AreEqual(SequenceMillisDelay * StreamLength, delay, DelayTolerance * 2, "Subscribe method blocked"); Assert.AreEqual(1, observer.NotificationThreadIds.Count, "Notified on more than one thread"); Assert.IsTrue(observer.NotificationThreadIds.Contains(Thread.CurrentThread.ManagedThreadId), "Not notified on main thread"); }
private void CheckNotificationsOnMainThread(IObservable <int> observable) { var observer = new TestUtils.TestObserver <int>(); DateTime before = DateTime.UtcNow; DateTime after; using (observable.Subscribe(observer)) { after = DateTime.UtcNow; observer.WaitForCompletion(); } int delay = (int)(after - before).TotalMilliseconds; var expectedMinimumDelay = SequenceMillisDelay * StreamLength; var expectedMaximumDelay = (int)(expectedMinimumDelay + (expectedMinimumDelay * DelayTolerancePercent)); delay.Should().BeInRange(expectedMinimumDelay, expectedMaximumDelay, "Subscribe method blocked"); observer.NotificationThreadIds.Should().ContainSingle("Notified on more than one thread"); observer.NotificationThreadIds.Should().Contain(Thread.CurrentThread.ManagedThreadId, "Not notified on main thread"); }