public void FastImmediateObserver_Ownership1() { var xs = new List<int>(); var o = Observer.Create<int>( xs.Add, ex => { }, () => { } ); var fio = new FastImmediateObserver<int>(o); var ts = new Task[16]; var N = 100; for (var i = 0; i < ts.Length; i++) { var j = i; ts[i] = Task.Factory.StartNew(() => { for (var k = 0; k < N; k++) { fio.OnNext(j * N + k); } fio.EnsureActive(N); }); } Task.WaitAll(ts); Assert.True(xs.Count == ts.Length * N); }
public void FastImmediateObserver_Ownership2() { var cd = new CountdownEvent(3); var w = new ManualResetEvent(false); var e = new ManualResetEvent(false); var xs = new List<int>(); var o = Observer.Create<int>( x => { xs.Add(x); w.Set(); e.WaitOne(); cd.Signal(); }, ex => { }, () => { } ); var fio = new FastImmediateObserver<int>(o); fio.OnNext(1); var t = Task.Factory.StartNew(() => { fio.EnsureActive(); }); w.WaitOne(); fio.OnNext(2); fio.OnNext(3); fio.EnsureActive(2); e.Set(); cd.Wait(); Assert.True(xs.Count == 3); }
public void FastImmediateObserver_Fault() { var xs = new List<int>(); var o = Observer.Create<int>( x => { xs.Add(x); if (x == 2) throw new Exception(); }, ex => { }, () => { } ); var fio = new FastImmediateObserver<int>(o); fio.OnNext(1); fio.OnNext(2); fio.OnNext(3); ReactiveAssert.Throws<Exception>(() => fio.EnsureActive()); fio.OnNext(4); fio.EnsureActive(); fio.OnNext(2); fio.EnsureActive(); Assert.True(xs.Count == 2); }