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);
        }
Esempio n. 2
0
        public void Cancel_Wait()
        {
            var cs  = new CompletableSubject();
            var cts = new CancellationTokenSource();

            try
            {
                Task.Factory.StartNew(() =>
                {
                    while (!cs.HasObserver())
                    {
                        ;
                    }

                    Thread.Sleep(100);

                    cts.Cancel();
                });

                cs
                .Wait(cts: cts);
                Assert.Fail();
            }
            catch (OperationCanceledException)
            {
                // expected
            }

            Assert.False(cs.HasObserver());
        }
Esempio n. 3
0
        public void Predicate_Dispose()
        {
            var count = 0;
            var us    = new CompletableSubject();

            var to = CompletableSource.Defer(() =>
            {
                if (count++ < 5)
                {
                    return(CompletableSource.Error(new InvalidOperationException()));
                }
                return(us);
            })
                     .Retry((e, c) => true)
                     .Test();

            to.AssertEmpty();

            Assert.True(us.HasObserver());

            to.Dispose();

            Assert.False(us.HasObserver());

            Assert.AreEqual(6, count);
        }
        public void Dispose()
        {
            var count = 0;
            var us    = new CompletableSubject();

            var to = CompletableSource.Defer(() =>
            {
                if (count++ < 5)
                {
                    return(CompletableSource.Empty());
                }
                return(us);
            })
                     .Repeat()
                     .Test();

            to.AssertEmpty();

            Assert.True(us.HasObserver());

            to.Dispose();

            Assert.False(us.HasObserver());

            Assert.AreEqual(6, count);
        }
        public void Dispose()
        {
            var d = new IDisposable[1];

            var cs = new CompletableSubject();

            var source = cs.Cache(c => d[0] = c);

            Assert.IsNull(d[0]);
            Assert.IsFalse(cs.HasObserver());

            var to1 = source.Test();

            Assert.IsNotNull(d[0]);
            Assert.IsTrue(cs.HasObserver());

            source.Test(true).AssertEmpty();

            d[0].Dispose();

            Assert.IsFalse(cs.HasObserver());

            to1.AssertFailure(typeof(OperationCanceledException));

            source.Test().AssertFailure(typeof(OperationCanceledException));
        }
        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);
        }
Esempio n. 7
0
        public void Observer_Dispose()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var cs = new CompletableSubject();

                var to = new TestObserver <object>();

                var cdl = new CountdownEvent(1);

                Task.Factory.StartNew(() =>
                {
                    while (!cs.HasObserver())
                    {
                        ;
                    }
                    to.Dispose();
                    cdl.Signal();
                });

                cs.BlockingSubscribe(to);

                cdl.Wait();

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

            var cs = new CompletableSubject();

            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 Single_Dispose_Inner()
        {
            var ss = new SingleSubject <int>();
            var cs = new CompletableSubject();

            var to = ss
                     .FlatMap(v => cs)
                     .Test();

            to.AssertSubscribed();

            Assert.True(ss.HasObserver());
            Assert.False(cs.HasObserver());

            ss.OnSuccess(1);

            Assert.True(cs.HasObserver());
            Assert.False(ss.HasObserver());

            to.AssertEmpty();

            cs.OnCompleted();

            to.AssertResult();
        }
        public void Dispose()
        {
            var cs = new CompletableSubject();

            var to = cs.Hide().Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());
        }
        public void Normal_Dispose()
        {
            var cs = new CompletableSubject();
            var to = new TestObserver <object>();

            cs.SubscribeSafe(to);

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());
        }
Esempio n. 12
0
        public void Dispose()
        {
            var cs = new CompletableSubject();

            var to = cs.Delay(TimeSpan.FromMinutes(5), NewThreadScheduler.Default)
                     .Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());
        }
        public void Observable_Dispose_Main()
        {
            var cs = new CompletableSubject();

            var to = cs
                     .AndThen(Observable.Range(1, 5))
                     .Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());
        }
Esempio n. 14
0
        public void Dispose_Empty()
        {
            var cs = new CompletableSubject();

            var to = cs
                     .ToMaybe <int>()
                     .Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());
        }
Esempio n. 15
0
        public void Dispose_Success()
        {
            var cs = new CompletableSubject();

            var to = cs
                     .ToMaybe(1)
                     .Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());
        }
Esempio n. 16
0
        public void Disposed()
        {
            var up = new CompletableSubject();

            IObservable <int> o = up.ToObservable <int>();

            var to = o.Test();

            Assert.True(up.HasObserver());

            to.Dispose();

            Assert.False(up.HasObserver());
        }
        public void Completable_Dispose_Next()
        {
            var us = new CompletableSubject();

            var to = CompletableSource.Empty()
                     .AndThen(us)
                     .Test();

            Assert.True(us.HasObserver());

            to.Dispose();

            Assert.False(us.HasObserver());
        }
        public void Single_Dispose_Main()
        {
            var cs = new CompletableSubject();

            var to = cs
                     .AndThen(SingleSource.Just(1))
                     .Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());
        }
Esempio n. 19
0
        public void Switch()
        {
            var s = new UnicastSubject <ICompletableSource>();

            var cs1 = new CompletableSubject();
            var cs2 = new CompletableSubject();
            var cs3 = new CompletableSubject();

            var to = s
                     .SwitchMap(v => v)
                     .Test();

            to.AssertEmpty();

            Assert.False(cs1.HasObserver());
            Assert.False(cs2.HasObserver());
            Assert.False(cs3.HasObserver());

            s.OnNext(cs1);

            Assert.True(cs1.HasObserver());
            Assert.False(cs2.HasObserver());
            Assert.False(cs3.HasObserver());

            cs1.OnCompleted();

            Assert.False(cs2.HasObserver());
            Assert.False(cs3.HasObserver());

            s.OnNext(cs2);

            Assert.True(cs2.HasObserver());
            Assert.False(cs3.HasObserver());

            s.OnNext(cs3);

            Assert.False(cs2.HasObserver());
            Assert.True(cs3.HasObserver());

            to.AssertEmpty();

            s.OnCompleted();

            to.AssertEmpty();

            cs3.OnCompleted();

            to.AssertResult();
        }
Esempio n. 20
0
        public void Array_Dispose_Max_Concurrency()
        {
            var cs1 = new CompletableSubject();
            var cs2 = new CompletableSubject();

            var to = CompletableSource.Merge(2, cs1, cs2)
                     .Test();

            Assert.True(cs1.HasObserver());
            Assert.True(cs2.HasObserver());

            to.Dispose();

            Assert.False(cs1.HasObserver());
            Assert.False(cs2.HasObserver());
        }
        public void Other_Dispose()
        {
            var ts = new CompletableSubject();

            var to = CompletableSource.Empty()
                     .DelaySubscription(ts)
                     .Test();

            Assert.True(ts.HasObserver());

            to.Dispose();

            Assert.False(ts.HasObserver());

            to.AssertEmpty();
        }
Esempio n. 22
0
        public void Dispose_Fallback()
        {
            var cs = new CompletableSubject();

            var to = CompletableSource.Error(new InvalidOperationException())
                     .OnErrorResumeNext(cs)
                     .Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());

            to.AssertEmpty();
        }
        public void Completable_Dispose_Main()
        {
            var cs    = new CompletableSubject();
            var count = 0;

            var to = cs
                     .AndThen(CompletableSource.FromAction(() => count++))
                     .Test();

            Assert.True(cs.HasObserver());

            to.Dispose();

            Assert.False(cs.HasObserver());

            Assert.AreEqual(0, count);
        }
        public void Crash_OnSubscribe()
        {
            var cs = new CompletableSubject();

            cs.SubscribeSafe(new FailingCompletableObserver(true, true, true));

            Assert.False(cs.HasObserver());
        }
        public void Basic_Second_Wins()
        {
            var cs1 = new CompletableSubject();
            var cs2 = new CompletableSubject();

            var to = CompletableSource.Amb(cs1, cs2).Test();

            to.AssertEmpty();

            Assert.True(cs1.HasObserver());
            Assert.True(cs2.HasObserver());

            cs2.OnCompleted();

            Assert.False(cs1.HasObserver());

            to.AssertResult();
        }
        public void Basic_Second_Wins_Error()
        {
            var cs1 = new CompletableSubject();
            var cs2 = new CompletableSubject();

            var to = CompletableSource.Amb(cs1, cs2).Test();

            to.AssertEmpty();

            Assert.True(cs1.HasObserver());
            Assert.True(cs2.HasObserver());

            cs2.OnError(new InvalidOperationException());

            Assert.False(cs1.HasObserver());

            to.AssertFailure(typeof(InvalidOperationException));
        }
Esempio n. 27
0
        public void Cancel()
        {
            var cts = new CancellationTokenSource();

            var cs = new CompletableSubject();

            var task = cs
                       .ToTask(cts);

            Assert.True(cs.HasObserver());

            Assert.False(task.IsCompleted);
            Assert.False(task.IsFaulted);

            cts.Cancel();

            Assert.False(cs.HasObserver());
        }
Esempio n. 28
0
        public void Dispose_Max_Concurrency()
        {
            var cs1 = new CompletableSubject();
            var cs2 = new CompletableSubject();

            var to = new[] { cs1, cs2 }
            .ToObservable()
            .FlatMap(v => v, maxConcurrency: 2)
            .Test();

            Assert.True(cs1.HasObserver());
            Assert.True(cs2.HasObserver());

            to.Dispose();

            Assert.False(cs1.HasObserver());
            Assert.False(cs2.HasObserver());
        }
Esempio n. 29
0
        public void Array_Error_Disposes_Other_Max_Concurrency()
        {
            var cs1 = new CompletableSubject();
            var cs2 = new CompletableSubject();

            var to = CompletableSource.Merge(2, cs1, cs2)
                     .Test();

            Assert.True(cs1.HasObserver());
            Assert.True(cs2.HasObserver());

            cs1.OnError(new InvalidOperationException());

            Assert.False(cs1.HasObserver());
            Assert.False(cs2.HasObserver());

            to.AssertFailure(typeof(InvalidOperationException));
        }
Esempio n. 30
0
        public void Dispose()
        {
            var cs = new CompletableSubject();

            var complete = 0;
            var error    = default(Exception);

            var d = cs.Subscribe(() => complete++, e => error = e);

            Assert.True(cs.HasObserver());

            d.Dispose();

            Assert.False(cs.HasObserver());

            Assert.AreEqual(0, complete);
            Assert.IsNull(error);
        }