public void Replay_Timeout_Revive()
        {
            var ts = new TestScheduler();

            var subj = new PublishSubject <int>();

            var src = subj.Replay().RefCount(TimeSpan.FromSeconds(1), ts);

            Assert.False(subj.HasObservers);

            var to = src.Test();

            Assert.True(subj.HasObservers);

            to.Dispose();

            Assert.True(subj.HasObservers);

            ts.AdvanceTimeBy(500);

            var to2 = src.Test();

            ts.AdvanceTimeBy(500);

            Assert.True(subj.HasObservers);

            subj.OnCompleted();

            Assert.False(ts.HasTasks());
        }
        public void Time_Dispose_Other()
        {
            var ts = new TestScheduler();

            var cs = new SingleSubject <int>();

            var to = cs
                     .DelaySubscription(TimeSpan.FromSeconds(1), ts)
                     .Test();

            Assert.False(cs.HasObserver());

            ts.AdvanceTimeBy(500);

            Assert.False(cs.HasObserver());

            ts.AdvanceTimeBy(500);

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());

            to.AssertEmpty();
        }
        public void Timeout_Fallback_Success()
        {
            var ts = new TestScheduler();
            var us = new SingleSubject <int>();

            var count = 0;
            var fb    = SingleSource.FromFunc <int>(() => ++ count);

            var to = us
                     .Timeout(TimeSpan.FromSeconds(1), ts, fb)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(100);

            Assert.True(us.HasObserver());

            ts.AdvanceTimeBy(900);

            Assert.False(us.HasObserver());

            to.AssertResult(1);

            Assert.AreEqual(1, count);
        }
        public void Timeout_Fallback()
        {
            var ts = new TestScheduler();
            var us = new CompletableSubject();

            var count = 0;
            var fb    = CompletableSource.FromAction(() => count++);

            var to = us
                     .Timeout(TimeSpan.FromSeconds(1), ts, fb)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(100);

            Assert.True(us.HasObserver());

            ts.AdvanceTimeBy(900);

            Assert.False(us.HasObserver());

            to.AssertResult();

            Assert.AreEqual(1, count);
        }
        public void Basic_Timed_Disposed()
        {
            var scheduler = new TestScheduler(1);

            Assert.AreEqual(scheduler.Now, DateTimeOffset.FromUnixTimeMilliseconds(1));

            Assert.False(scheduler.HasTasks());

            var count = 0;

            var d = scheduler.Schedule((object)null, TimeSpan.FromSeconds(1), (sch, state) => {
                count++;
                return(DisposableHelper.EMPTY);
            });

            Assert.True(scheduler.HasTasks());

            Assert.AreEqual(0, count);

            scheduler.AdvanceTimeBy(500);

            Assert.AreEqual(0, count);

            d.Dispose();

            scheduler.AdvanceTimeBy(500);

            Assert.AreEqual(0, count);

            Assert.False(scheduler.HasTasks());
        }
示例#6
0
        public void Step()
        {
            var subj = new PublishSubject <int>();
            var ts   = new TestScheduler();

            var to = subj.TakeLast(TimeSpan.FromMilliseconds(500), ts)
                     .Test();

            to.AssertEmpty();

            subj.OnNext(1);

            ts.AdvanceTimeBy(200);

            subj.OnNext(2);

            ts.AdvanceTimeBy(200);

            subj.OnNext(3);

            ts.AdvanceTimeBy(200);

            subj.OnNext(4);

            ts.AdvanceTimeBy(200);

            to.AssertEmpty();

            subj.OnCompleted();

            to.AssertResult(3, 4);
        }
        public void Timeout_Fallback_Error()
        {
            var ts = new TestScheduler();
            var us = new CompletableSubject();

            var count = 0;
            var fb    = CompletableSource.FromAction(() =>
            {
                ++count;
                throw new InvalidOperationException();
            });

            var to = us
                     .Timeout(TimeSpan.FromSeconds(1), ts, fb)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(100);

            Assert.True(us.HasObserver());

            ts.AdvanceTimeBy(900);

            Assert.False(us.HasObserver());

            to.AssertFailure(typeof(InvalidOperationException));

            Assert.AreEqual(1, count);
        }
        public void Basic()
        {
            var ts = new TestScheduler();

            var subj = new PublishSubject <int>();

            var to = subj.SkipLast(TimeSpan.FromSeconds(5), ts).Test();

            to.AssertEmpty();

            subj.OnNext(1);

            ts.AdvanceTimeBy(1000);

            to.AssertEmpty();

            subj.OnNext(2);

            ts.AdvanceTimeBy(4000);

            subj.OnNext(3);

            to.AssertValuesOnly(1);

            ts.AdvanceTimeBy(1000);

            subj.OnNext(4);

            to.AssertValuesOnly(1, 2);

            subj.OnCompleted();

            to.AssertResult(1, 2);
        }
示例#9
0
        public void Regular_Step_InitialDelay()
        {
            var ts = new TestScheduler();

            var to = ObservableSource.IntervalRange(1, 5, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(1), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(5);

            to.AssertEmpty();

            ts.AdvanceTimeBy(5);

            to.AssertValuesOnly(1);

            ts.AdvanceTimeBy(2);

            to.AssertValuesOnly(1, 2, 3);

            ts.AdvanceTimeBy(2);

            to.AssertResult(1, 2, 3, 4, 5);
        }
示例#10
0
        public void Fused_Step_InitialDelay()
        {
            var ts = new TestScheduler();

            var to = ObservableSource.IntervalRange(1, 5, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(1), ts)
                     .Test(fusionMode: FusionSupport.Any)
                     .AssertFuseable()
                     .AssertFusionMode(FusionSupport.Async);

            to.AssertEmpty();

            ts.AdvanceTimeBy(5);

            to.AssertEmpty();

            ts.AdvanceTimeBy(5);

            to.AssertValuesOnly(1);

            ts.AdvanceTimeBy(2);

            to.AssertValuesOnly(1, 2, 3);

            ts.AdvanceTimeBy(2);

            to.AssertResult(1, 2, 3, 4, 5);
        }
示例#11
0
        public void Time_Step()
        {
            var ts = new TestScheduler();

            var subj = new PublishSubject <int>();

            var to = subj.Delay(v => ObservableSource.Timer(TimeSpan.FromSeconds(1), ts)).Test();

            subj.OnNext(1);
            subj.OnNext(2);

            Assert.True(ts.HasTasks());

            to.AssertEmpty();

            ts.AdvanceTimeBy(1000);

            to.AssertValuesOnly(1, 2);

            ts.AdvanceTimeBy(1000);

            to.AssertValuesOnly(1, 2);

            subj.OnNext(3);

            ts.AdvanceTimeBy(200);

            subj.OnNext(4);

            ts.AdvanceTimeBy(200);

            subj.OnNext(5);

            ts.AdvanceTimeBy(200);

            to.AssertValuesOnly(1, 2);

            ts.AdvanceTimeBy(400);

            to.AssertValuesOnly(1, 2, 3);

            ts.AdvanceTimeBy(200);

            to.AssertValuesOnly(1, 2, 3, 4);

            ts.AdvanceTimeBy(200);

            to.AssertValuesOnly(1, 2, 3, 4, 5);

            subj.OnCompleted();

            ts.AdvanceTimeBy(500);

            to.AssertResult(1, 2, 3, 4, 5);

            Assert.False(ts.HasTasks());
        }
        public void Regular_Regular_Error_Delayed()
        {
            for (int i = 0; i < 2; i++)
            {
                var ts   = new TestScheduler();
                var subj = new PublishSubject <int>();

                var to = subj.ObserveOn(ts, true, fair: i == 0)
                         .Test()
                         .WithTag($"fair={i == 0}");

                Assert.True(subj.HasObservers);

                to.AssertEmpty();

                subj.OnNext(1);
                subj.OnNext(2);
                subj.OnError(new InvalidOperationException());

                to.AssertEmpty();

                ts.AdvanceTimeBy(1);

                to.AssertFailure(typeof(InvalidOperationException), 1, 2);
            }
        }
        public void Time_Dispose()
        {
            var ts = new TestScheduler();

            var to = SingleSource.Just(1)
                     .DelaySubscription(TimeSpan.FromSeconds(1), ts)
                     .Test();

            ts.AdvanceTimeBy(500);

            to.Dispose();

            ts.AdvanceTimeBy(500);

            to.AssertEmpty();
        }
        public void Regular_Dispose()
        {
            var ts = new TestScheduler();

            var to = ObservableSource.Timer(TimeSpan.FromSeconds(1), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.Dispose();

            ts.AdvanceTimeBy(500);

            to.AssertEmpty();
        }
        public void Success_Step()
        {
            var ts = new TestScheduler();

            var to = MaybeSource.Just(1)
                     .Delay(TimeSpan.FromSeconds(1), ts).Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertResult(1);
        }
示例#16
0
        public void Error_Step()
        {
            var ts = new TestScheduler();

            var to = CompletableSource.Error(new InvalidOperationException())
                     .Delay(TimeSpan.FromSeconds(1), ts).Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertFailure(typeof(InvalidOperationException));
        }
示例#17
0
        public void Basic_Step()
        {
            var ts = new TestScheduler();

            var to = CompletableSource.Empty()
                     .Delay(TimeSpan.FromSeconds(1), ts).Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertResult();
        }
示例#18
0
        public void Dispose()
        {
            var sch = new TestScheduler();
            var to  = MaybeSource.Timer(TimeSpan.FromMilliseconds(100), sch)
                      .Test();

            Assert.True(sch.HasTasks());

            sch.AdvanceTimeBy(50);

            Assert.True(sch.HasTasks());
            to.AssertEmpty();

            sch.AdvanceTimeBy(50);

            Assert.False(sch.HasTasks());
            to.AssertResult(0L);
        }
        public void Fused_Basic2()
        {
            var ts = new TestScheduler();

            var to = ObservableSource.Timer(TimeSpan.FromSeconds(1), ts)
                     .Test(fusionMode: FusionSupport.Any)
                     .AssertFuseable()
                     .AssertFusionMode(FusionSupport.Async);

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertResult(0L);
        }
        public void No_Timeout()
        {
            var ts = new TestScheduler();
            var us = new CompletableSubject();

            var to = us
                     .Timeout(TimeSpan.FromSeconds(1), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(100);

            Assert.True(us.HasObserver());

            us.OnCompleted();

            ts.AdvanceTimeBy(900);

            to.AssertResult();
        }
        public void No_Timeout_Error()
        {
            var ts = new TestScheduler();
            var us = new CompletableSubject();

            var to = us
                     .Timeout(TimeSpan.FromSeconds(1), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(100);

            Assert.True(us.HasObserver());

            us.OnError(new InvalidOperationException());

            ts.AdvanceTimeBy(900);

            to.AssertFailure(typeof(InvalidOperationException));
        }
        public void Timeout()
        {
            var ts = new TestScheduler();
            var us = new CompletableSubject();

            var to = us
                     .Timeout(TimeSpan.FromSeconds(1), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(100);

            Assert.True(us.HasObserver());

            ts.AdvanceTimeBy(900);

            Assert.False(us.HasObserver());

            to.AssertFailure(typeof(TimeoutException));
        }
        public void No_Timeout_Success()
        {
            var ts = new TestScheduler();
            var us = new SingleSubject <int>();

            var to = us
                     .Timeout(TimeSpan.FromSeconds(1), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(100);

            Assert.True(us.HasObserver());

            us.OnSuccess(1);

            ts.AdvanceTimeBy(900);

            to.AssertResult(1);
        }
示例#24
0
        public void retries_indefinitely_if_no_retry_count_specified()
        {
            var tries  = 0;
            var source = Observable.Defer(() => {
                ++tries;
                return(Observable.Throw <Unit>(new Exception()));
            });

            source.RetryWithBackoff(scheduler: TestScheduler).Subscribe(_ => { }, _ => { });
            TestScheduler.AdvanceTimeBy(TimeSpan.FromDays(1));

            tries.ShouldBe(486);
        }
示例#25
0
        public void Timed_Timeout()
        {
            var ts = new TestScheduler();

            var to = ObservableSource.Never <int>()
                     .Timeout(TimeSpan.FromSeconds(1), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(1000);

            to.AssertFailure(typeof(TimeoutException));
        }
        public void Dispose_Fallback()
        {
            var ts = new TestScheduler();
            var us = new CompletableSubject();

            var to = CompletableSource.Never()
                     .Timeout(TimeSpan.FromSeconds(1), ts, us)
                     .Test();

            ts.AdvanceTimeBy(100);

            Assert.False(us.HasObserver());

            ts.AdvanceTimeBy(900);

            Assert.True(us.HasObserver());

            to.Dispose();

            Assert.False(us.HasObserver());

            to.AssertEmpty();
        }
示例#27
0
        public void Timed_Timeout_Fallback()
        {
            var ts = new TestScheduler();

            var to = ObservableSource.Never <int>()
                     .Timeout(TimeSpan.FromSeconds(1), ts, ObservableSource.Range(6, 5))
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(1000);

            to.AssertResult(6, 7, 8, 9, 10);
        }
示例#28
0
        public void Timed_Fallback_Error()
        {
            var ts = new TestScheduler();

            var to = ObservableSource.Never <int>()
                     .Timeout(TimeSpan.FromSeconds(1), ts, ObservableSource.Error <int>(new InvalidOperationException()))
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(1000);

            to.AssertFailure(typeof(InvalidOperationException));
        }
        public void Negative_Past_DateTimeOffset()
        {
            var scheduler = new TestScheduler(10000);

            var count = 0;

            scheduler.Schedule((object)null, DateTimeOffset.FromUnixTimeMilliseconds(0), (sch, state) => {
                count++;
                return(DisposableHelper.EMPTY);
            });

            scheduler.AdvanceTimeBy(500);

            Assert.AreEqual(1, count);

            Assert.False(scheduler.HasTasks());
        }
        public void Negative_Timespan()
        {
            var scheduler = new TestScheduler(1);

            var count = 0;

            scheduler.Schedule((object)null, TimeSpan.FromSeconds(-1), (sch, state) => {
                count++;
                return(DisposableHelper.EMPTY);
            });

            scheduler.AdvanceTimeBy(500);

            Assert.AreEqual(1, count);

            Assert.False(scheduler.HasTasks());
        }