public void WaitForOperatorThrowsTimeoutExceptionAfterTimeOut() { var scheduler = new TestFacade(); var synced = new Synced <Exception>(); async CTask Do() { var source = new Source <int>(); var waitedFor = source.WaitFor(5, true, TimeSpan.FromMilliseconds(500)); try { await waitedFor; } catch (Exception e) { synced.Value = e; } } synced.Value.ShouldBeNull(); scheduler.Schedule(() => _ = Do()); var exception = synced.WaitFor(e => e != null); (exception is TimeoutException).ShouldBeTrue(); scheduler.Dispose(); }
public void EnqueuedWorkIsExecuted() { var value = new Synced <int>(); var queueWorker = new QueueWorker(); queueWorker.Do(() => value.Value = 10); value.WaitFor(i => i == 10); }
public void DelegatesAndSchedulerAreSetAfterStartingTheScheduler() { var objectStore = ObjectStore.New(new InMemoryStorageEngine()); var syncs = new SynchronizationQueue(); var scheduler = new InternalScheduler(objectStore, new ReadyToSchedules(), syncs, new Engine(), false); scheduler.Start(); var synced = new Synced <bool>(); scheduler.Schedule(() => synced.Value = Roots.Instance.Value == objectStore.Roots, false); synced.WaitFor(d => synced.Value); scheduler.Dispose(); }
public void WaitForOperatorEmitsElementsBeforeTimeOut() { var testFacade = new TestFacade(); var synced = new Synced <Tuple <Exception, int[]> >(); async CTask Do() { var source = new Source <int>(); var waitedFor = source.WaitFor(5, true, TimeSpan.FromMilliseconds(500)); for (var i = 0; i < 5; i++) { await Sleep.Until(10, false); source.Emit(i); } try { var elements = await waitedFor; synced.Value = Tuple.Create(default(Exception), elements.ToArray()); } catch (Exception e) { synced.Value = Tuple.Create(e, default(int[])); } } synced.Value.ShouldBeNull(); testFacade.Schedule(() => _ = Do()); var(exception, elements) = synced.WaitFor(e => e != null); exception.ShouldBeNull(); elements.Length.ShouldBe(5); for (var i = 0; i < 5; i++) { elements[i].ShouldBe(i); } }
public void WorkQueueIsSwappedCorrectlyOnLongRunningWorkAsync() { var value1 = new Synced <bool>(); var value2 = new Synced <bool>(); var queueWorker = new QueueWorker(); queueWorker.Do(async() => { await Task.Delay(500); value1.Value = true; }); queueWorker.Do(() => { value2.Value = true; return(Task.CompletedTask); }); value2.WaitFor(b => b); value1.Value.ShouldBe(true); }
public void WorkQueueIsSwappedCorrectlyOnLongRunningWork() { var value1 = new Synced <bool>(); var value2 = new Synced <bool>(); var queueWorker = new QueueWorker(); queueWorker.Do(() => { Thread.Sleep(200); value1.Value = true; }); Thread.Sleep(100); queueWorker.Do(() => { Thread.Sleep(200); value2.Value = true; }); value2.WaitFor(b => b); value1.Value.ShouldBe(true); }