public async Task TestEnqueueReceiveEvents() { int numMessages = 10000; var logger = new TestOutputLogger(this.TestOutput, false); using var queue = new TestEventQueue(logger, (notification, evt, _) => { }); var enqueueTask = Task.Run(() => { for (int i = 0; i < numMessages; i++) { queue.Enqueue(new E1(), null, null); } }); var receiveTask = Task.Run(async() => { for (int i = 0; i < numMessages; i++) { await queue.ReceiveEventAsync(typeof(E1)); } }); await Task.WhenAny(Task.WhenAll(enqueueTask, receiveTask), Task.Delay(3000)); Assert.True(enqueueTask.IsCompleted); Assert.True(receiveTask.IsCompleted); }
public async Task TestEnqueueDequeueEvents() { int numMessages = 10000; var logger = new TestOutputLogger(this.TestOutput, false); using var queue = new TestEventQueue(logger, (notification, evt, _) => { }); var enqueueTask = Task.Run(() => { for (int i = 0; i < numMessages; i++) { queue.Enqueue(new E1(), null, null); } }); var dequeueTask = Task.Run(() => { for (int i = 0; i < numMessages; i++) { var(deqeueStatus, e, g, info) = queue.Dequeue(); if (deqeueStatus is DequeueStatus.Success) { Assert.IsType <E1>(e); } } }); await Task.WhenAny(Task.WhenAll(enqueueTask, dequeueTask), Task.Delay(3000)); Assert.True(enqueueTask.IsCompleted); Assert.True(dequeueTask.IsCompleted); }
public void TestEnqueueEvent() { var logger = new TestOutputLogger(this.TestOutput, false); using var queue = new TestEventQueue(logger, (notification, evt, _) => { }); Assert.Equal(0, queue.Size); var enqueueStatus = queue.Enqueue(new E1(), null, null); Assert.Equal(1, queue.Size); Assert.Equal(EnqueueStatus.EventHandlerRunning, enqueueStatus); enqueueStatus = queue.Enqueue(new E2(), null, null); Assert.Equal(2, queue.Size); Assert.Equal(EnqueueStatus.EventHandlerRunning, enqueueStatus); enqueueStatus = queue.Enqueue(new E3(), null, null); Assert.Equal(3, queue.Size); Assert.Equal(EnqueueStatus.EventHandlerRunning, enqueueStatus); }
public void TestDequeueEvent() { var logger = new TestOutputLogger(this.TestOutput, false); using var queue = new TestEventQueue(logger, (notification, evt, _) => { }); var(deqeueStatus, e, group, info) = queue.Dequeue(); Assert.Equal(DequeueStatus.Unavailable, deqeueStatus); Assert.Equal(0, queue.Size); queue.Enqueue(new E1(), null, null); (deqeueStatus, e, group, info) = queue.Dequeue(); Assert.IsType <E1>(e); Assert.Equal(DequeueStatus.Success, deqeueStatus); Assert.Equal(0, queue.Size); queue.Enqueue(new E3(), null, null); queue.Enqueue(new E2(), null, null); queue.Enqueue(new E1(), null, null); (deqeueStatus, e, group, info) = queue.Dequeue(); Assert.IsType <E3>(e); Assert.Equal(DequeueStatus.Success, deqeueStatus); Assert.Equal(2, queue.Size); (deqeueStatus, e, group, info) = queue.Dequeue(); Assert.IsType <E2>(e); Assert.Equal(DequeueStatus.Success, deqeueStatus); Assert.Equal(1, queue.Size); (deqeueStatus, e, group, info) = queue.Dequeue(); Assert.IsType <E1>(e); Assert.Equal(DequeueStatus.Success, deqeueStatus); Assert.Equal(0, queue.Size); (deqeueStatus, e, group, info) = queue.Dequeue(); Assert.Equal(DequeueStatus.Unavailable, deqeueStatus); Assert.Equal(0, queue.Size); }
public void TestEnqueueEventWithHandlerNotRunning() { var logger = new TestOutputLogger(this.TestOutput, false); using var queue = new TestEventQueue(logger, (notification, evt, _) => { }); var(deqeueStatus, e, group, info) = queue.Dequeue(); Assert.Equal(DequeueStatus.Unavailable, deqeueStatus); Assert.Equal(0, queue.Size); var enqueueStatus = queue.Enqueue(new E1(), null, null); Assert.Equal(EnqueueStatus.EventHandlerNotRunning, enqueueStatus); Assert.Equal(1, queue.Size); }