public void Race_Action() { for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var us = new MonocastSubject <int>(); var to = new TestObserver <int>(); TestHelper.Race(() => { for (int j = 0; j < 1000; j++) { us.OnNext(j); } us.OnCompleted(); }, () => { us.BlockingSubscribe(to.OnNext, to.OnError, to.OnCompleted); }); to.AssertValueCount(1000) .AssertNoError() .AssertCompleted(); } }
public void Basic_Observer_Dispose() { var to = new TestObserver <int>(); var cdl = new CountdownEvent(2); var us = new MonocastSubject <int>(); Task.Factory.StartNew(() => { while (to.ItemCount != 5) { ; } to.Dispose(); cdl.Signal(); }); Task.Factory.StartNew(() => { us.Emit(1, 2, 3, 4, 5); cdl.Signal(); }); us.BlockingSubscribe(to); to.AssertValuesOnly(1, 2, 3, 4, 5); Assert.True(cdl.Wait(3000)); Assert.False(us.HasObserver()); }
public void Basic_Action_Dispose() { var to = new TestObserver <int>(); var sad = new SingleAssignmentDisposable(); var cdl = new CountdownEvent(2); var us = new MonocastSubject <int>(); Task.Factory.StartNew(() => { while (to.ItemCount != 5) { ; } sad.Dispose(); cdl.Signal(); }); Task.Factory.StartNew(() => { us.Emit(1, 2, 3, 4, 5); cdl.Signal(); }); us.BlockingSubscribe(to.OnNext, to.OnError, to.OnCompleted, d => sad.Disposable = d); to.AssertValuesOnly(1, 2, 3, 4, 5); Assert.True(cdl.Wait(3000)); Assert.False(us.HasObserver()); }