public void TimeInterval_Regular() { var scheduler = new TestScheduler(); var xs = scheduler.CreateHotObservable( OnNext(150, 1), OnNext(210, 2), OnNext(230, 3), OnNext(260, 4), OnNext(300, 5), OnNext(350, 6), OnCompleted <int>(400) ); var res = scheduler.Start(() => xs.TimeInterval(scheduler.DisableOptimizations()) ); res.Messages.AssertEqual( OnNext(210, new TimeInterval <int>(2, TimeSpan.FromTicks(10))), OnNext(230, new TimeInterval <int>(3, TimeSpan.FromTicks(20))), OnNext(260, new TimeInterval <int>(4, TimeSpan.FromTicks(30))), OnNext(300, new TimeInterval <int>(5, TimeSpan.FromTicks(40))), OnNext(350, new TimeInterval <int>(6, TimeSpan.FromTicks(50))), OnCompleted <TimeInterval <int> >(400) ); xs.Subscriptions.AssertEqual( Subscribe(200, 400) ); }
public void TimeInterval_Never() { var scheduler = new TestScheduler(); var xs = scheduler.CreateHotObservable( OnNext(150, 1) ); var res = scheduler.Start(() => xs.TimeInterval(scheduler.DisableOptimizations()) ); res.Messages.AssertEqual( ); xs.Subscriptions.AssertEqual( Subscribe(200, 1000) ); }
public void TimeInterval_Empty() { var scheduler = new TestScheduler(); var xs = scheduler.CreateHotObservable( OnNext(150, 1), OnCompleted <int>(300) ); var res = scheduler.Start(() => xs.TimeInterval(scheduler.DisableOptimizations()) ); res.Messages.AssertEqual( OnCompleted <TimeInterval <int> >(300) ); xs.Subscriptions.AssertEqual( Subscribe(200, 300) ); }
public void RepeatingTimer_NoStopwatch_Slippage2() { var scheduler = new TestScheduler(); var xs = default(IObservable <long>); scheduler.ScheduleAbsolute(100, () => { xs = Observable.Timer(TimeSpan.FromTicks(100), TimeSpan.FromTicks(100), scheduler.DisableOptimizations(typeof(IStopwatchProvider))); }); var times = new List <long>(); var onNext = new Action <long>(x => { times.Add(scheduler.Clock); if (x == 0) { return; } if (x < 2) { scheduler.Sleep(50); return; } if (x < 4) { scheduler.Sleep(120); return; } if (x < 6) { scheduler.Sleep(50); return; } if (x < 8) { return; } }); var d = default(IDisposable); scheduler.ScheduleAbsolute(200, () => { d = xs.Subscribe(onNext); }); scheduler.ScheduleAbsolute(1000, () => { d.Dispose(); }); scheduler.Start(); times.AssertEqual( 300, 400, 500, 622, // 2 off because of 500 + 120 + 2 scheduling ticks (one due to yield in SchedulePeriodic emulation code) 744, // 4 off because of 622 + 120 + 2 scheduling ticks (one due to yield in SchedulePeriodic emulation code) 842, // | 942 // +--> 42 off because this situation (no stopwatch or periodic scheduling interface) only gets best effort treatment (see SchedulePeriodic emulation code) ); }
public void RepeatingTimer_NoStopwatch_Slippage1() { var scheduler = new TestScheduler(); var xs = default(IObservable <long>); scheduler.ScheduleAbsolute(100, () => { xs = Observable.Timer(TimeSpan.Zero, TimeSpan.FromTicks(100), scheduler.DisableOptimizations(typeof(IStopwatchProvider))); }); var times = new List <long>(); var onNext = new Action <long>(x => { times.Add(scheduler.Clock); if (x == 0) { return; } if (x < 2) { scheduler.Sleep(50); return; } if (x < 4) { scheduler.Sleep(120); return; } if (x < 6) { scheduler.Sleep(50); return; } if (x < 8) { return; } }); var d = default(IDisposable); scheduler.ScheduleAbsolute(200, () => { d = xs.Subscribe(onNext); }); scheduler.ScheduleAbsolute(1000, () => { d.Dispose(); }); scheduler.Start(); times.AssertEqual( 201, // 1 off because of initial scheduling jump (InvokeStart) 301, 401, 523, // 3 off because of 401 + 120 + 2 scheduling ticks (one due to yield in SchedulePeriodic emulation code) 645, // 5 off because of 523 + 120 + 2 scheduling ticks (one due to yield in SchedulePeriodic emulation code) 743, // \ 843, // +--> 43 off because this situation (no stopwatch or periodic scheduling interface) only gets best effort treatment (see SchedulePeriodic emulation code) 943 // / ); }