public void Wait_AfterSet_IsCompleted() { var mre = new AsyncManualResetEvent(); mre.Set(); mre.Wait(); }
public void WaitAsync_Set_IsCompleted() { var mre = new AsyncManualResetEvent(true); var task = mre.WaitAsync(); Assert.IsTrue(task.IsCompleted); }
public void MultipleWaitAsync_AfterSet_IsCompleted() { var mre = new AsyncManualResetEvent(); mre.Set(); var task1 = mre.WaitAsync(); var task2 = mre.WaitAsync(); Assert.IsTrue(task1.IsCompleted); Assert.IsTrue(task2.IsCompleted); }
public void Wait_Unset_IsNotCompleted() { Test.Async(async () => { var mre = new AsyncManualResetEvent(); var task = TaskShim.Run(() => mre.Wait()); await AssertEx.NeverCompletesAsync(task); }); }
public void WaitAsync_Unset_IsNotCompleted() { AsyncContext.Run(async () => { var mre = new AsyncManualResetEvent(); var task = mre.WaitAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public virtual async Task CanHandleNullMessage() { var messageBus = GetMessageBus(); if (messageBus == null) return; using (messageBus) { var resetEvent = new AsyncManualResetEvent(false); messageBus.Subscribe<object>(msg => { throw new ApplicationException(); }); await Task.Delay(100); await messageBus.PublishAsync<object>(null); Trace.WriteLine("Published one..."); await resetEvent.WaitAsync(TimeSpan.FromSeconds(1)); } }
public virtual async Task CanHandleNullMessage() { var messageBus = GetMessageBus(); if (messageBus == null) return; using (messageBus) { var resetEvent = new AsyncManualResetEvent(false); messageBus.Subscribe<object>(msg => { resetEvent.Set(); throw new Exception(); }); await SystemClock.SleepAsync(100); await messageBus.PublishAsync<object>(null); _logger.Trace("Published one..."); await resetEvent.WaitAsync(TimeSpan.FromSeconds(1)); } }
public virtual async Task CanSendMessage() { var messageBus = GetMessageBus(); if (messageBus == null) return; using (messageBus) { var resetEvent = new AsyncManualResetEvent(false); messageBus.Subscribe<SimpleMessageA>(msg => { Logger.Trace().Message("Got message").Write(); Assert.Equal("Hello", msg.Data); resetEvent.Set(); Logger.Trace().Message("Set event").Write(); }); await Task.Delay(100); await messageBus.PublishAsync(new SimpleMessageA { Data = "Hello" }); Trace.WriteLine("Published one..."); await resetEvent.WaitAsync(TimeSpan.FromSeconds(5)); } }
public virtual async Task CanSendDerivedMessage() { var messageBus = GetMessageBus(); if (messageBus == null) return; using (messageBus) { var resetEvent = new AsyncManualResetEvent(false); messageBus.Subscribe<SimpleMessageA>(msg => { _logger.Trace("Got message"); Assert.Equal("Hello", msg.Data); resetEvent.Set(); _logger.Trace("Set event"); }); await SystemClock.SleepAsync(100); await messageBus.PublishAsync(new DerivedSimpleMessageA { Data = "Hello" }); _logger.Trace("Published one..."); await resetEvent.WaitAsync(TimeSpan.FromSeconds(5)); } }
public virtual async Task WillOnlyReceiveSubscribedMessageType() { var messageBus = GetMessageBus(); if (messageBus == null) return; using (messageBus) { var resetEvent = new AsyncManualResetEvent(false); messageBus.Subscribe<SimpleMessageB>(msg => { Assert.True(false, "Received wrong message type."); }); messageBus.Subscribe<SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); resetEvent.Set(); }); await messageBus.PublishAsync(new SimpleMessageA { Data = "Hello" }); await resetEvent.WaitAsync(TimeSpan.FromSeconds(2)); } }
public void Id_IsNotZero() { var mre = new AsyncManualResetEvent(); Assert.AreNotEqual(0, mre.Id); }
public DebugView(AsyncManualResetEvent mre) { _mre = mre; }
public virtual async Task CanUseQueueWorker() { var queue = GetQueue(); if (queue == null) return; using (queue) { await queue.DeleteQueueAsync(); var resetEvent = new AsyncManualResetEvent(false); queue.StartWorking(async w => { Assert.Equal("Hello", w.Value.Data); await w.CompleteAsync(); resetEvent.Set(); }); await queue.EnqueueAsync(new SimpleWorkItem { Data = "Hello" }); await resetEvent.WaitAsync(); var stats = await queue.GetQueueStatsAsync(); Assert.Equal(1, stats.Completed); Assert.Equal(0, stats.Queued); Assert.Equal(0, stats.Errors); } }
/// <summary> /// Creates an async-compatible countdown event. /// </summary> /// <param name="count">The number of signals this event will need before it becomes set.</param> public AsyncCountdownEvent(long count) { _mre = new AsyncManualResetEvent(count == 0); _count = count; }
internal PauseToken(AsyncManualResetEvent mre) { _mre = mre; }
public void Wait_Set_IsCompleted() { var mre = new AsyncManualResetEvent(true); mre.Wait(); }
public DebugView(AsyncManualResetEvent mre) { _mre = mre; }
public virtual async Task CanAutoCompleteWorker() { var queue = GetQueue(); if (queue == null) return; using (queue) { await queue.DeleteQueueAsync(); var resetEvent = new AsyncManualResetEvent(false); queue.StartWorking(w => { Assert.Equal("Hello", w.Value.Data); resetEvent.Set(); return TaskHelper.Completed(); }, true); await queue.EnqueueAsync(new SimpleWorkItem { Data = "Hello" }); Assert.Equal(1, (await queue.GetQueueStatsAsync()).Enqueued); await resetEvent.WaitAsync(TimeSpan.FromSeconds(2)); await Task.Delay(10); var stats = await queue.GetQueueStatsAsync(); Assert.Equal(0, stats.Queued); Assert.Equal(1, stats.Completed); Assert.Equal(0, stats.Errors); } }
internal PauseToken(AsyncManualResetEvent mre) { _mre = mre; }
public void WaitAsync_AfterReset_IsNotCompleted() { Test.Async(async () => { var mre = new AsyncManualResetEvent(); mre.Set(); mre.Reset(); var task = mre.WaitAsync(); await AssertEx.NeverCompletesAsync(task); }); }