public void Limited_Eager_Race_Success_Empty()
        {
            for (int k = 1; k < 10; k++)
            {
                for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
                {
                    var ms1 = new MaybeSubject <int>();
                    var ms2 = new MaybeSubject <int>();

                    var to = new[] {
                        ms1, ms2
                    }
                    .ToObservable()
                    .FlatMap(v => v, maxConcurrency: k)
                    .Test();

                    TestHelper.Race(() =>
                    {
                        ms1.OnSuccess(1);
                    }, () =>
                    {
                        ms2.OnCompleted();
                    });

                    to.AssertResult(1);
                }
            }
        }
        public void Limited_Eager_Main_Completes_Inner_Empty()
        {
            for (int k = 1; k < 10; k++)
            {
                var subj = new Subject <int>();
                var ms   = new MaybeSubject <int>();

                var to = subj.FlatMap(v => ms, maxConcurrency: k).Test();

                Assert.True(subj.HasObservers);
                Assert.False(ms.HasObserver());

                subj.OnNext(1);
                subj.OnCompleted();

                Assert.True(ms.HasObserver());

                ms.OnCompleted();

                Assert.False(subj.HasObservers);
                Assert.False(ms.HasObserver());

                to.AssertResult();
            }
        }
        public void Limited_Delayed_Race_Empty()
        {
            for (int k = 1; k < 10; k++)
            {
                for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
                {
                    var ms1 = new MaybeSubject <int>();
                    var ms2 = new MaybeSubject <int>();

                    var to = new[] {
                        ms1, ms2
                    }
                    .ToObservable()
                    .FlatMap(v => v, true, k)
                    .Test();

                    TestHelper.Race(() =>
                    {
                        ms1.OnCompleted();
                    }, () =>
                    {
                        ms2.OnCompleted();
                    });

                    to.AssertResult();
                }
            }
        }
        public void Max_Delayed_Main_Completes_Inner_Empty()
        {
            var subj = new Subject <int>();
            var ms   = new MaybeSubject <int>();

            var to = subj.FlatMap(v => ms, true).Test();

            Assert.True(subj.HasObservers);
            Assert.False(ms.HasObserver());

            subj.OnNext(1);
            subj.OnCompleted();

            Assert.True(ms.HasObserver());

            ms.OnCompleted();

            Assert.False(subj.HasObservers);
            Assert.False(ms.HasObserver());

            to.AssertResult();
        }
        public void Max_Eager_Race_Empty()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var ms1 = new MaybeSubject <int>();
                var ms2 = new MaybeSubject <int>();

                var to = new[] {
                    ms1, ms2
                }
                .ToObservable()
                .FlatMap(v => v)
                .Test();

                TestHelper.Race(() => {
                    ms1.OnCompleted();
                }, () => {
                    ms2.OnCompleted();
                });

                to.AssertResult();
            }
        }