public void IsEmpty_WithTwoItems_IsFalse() { var queue = new WaitQueue<int>(); queue.Enqueue(item0, none).WaitEx(); queue.Enqueue(item1, none).WaitEx(); Assert.IsFalse(queue.IsEmpty(none).ResultEx()); }
public void Dequeue_EndEnqueue_IsComplete() { var queue = new WaitQueue<int>(); var task1 = queue.Enqueue(item0, none); var task2 = queue.Enqueue(item1, none); Test.Async(async () => { await task1; await task2; Assert.IsFalse(await queue.IsEmpty(none)); Assert.IsFalse(await queue.IsComplete(none)); Assert.IsFalse(await queue.IsEnded(none)); await queue.EndEnqueue(none); Assert.IsTrue(await queue.IsEnded(none)); Assert.IsFalse(await queue.IsEmpty(none)); Assert.IsFalse(await queue.IsComplete(none)); while (queue.Count > 0) await queue.Dequeue(none); Assert.IsTrue(await queue.IsComplete(none)); Assert.IsTrue(await queue.IsEmpty(none)); Assert.IsTrue(await queue.IsEnded(none)); }); Assert.IsTrue(task1.IsCompleted); Assert.IsTrue(task2.IsCompleted); }
public void IsEmpty_WhenEmpty_IsTrue() { var queue = new WaitQueue<int>(); Assert.IsTrue(queue.IsEmpty(none).ResultEx()); }
public void Cancelled_BeforeDequeue_Faults() { var queue = new WaitQueue<int>(); var cts = new CancellationTokenSource(); cts.Cancel(); var task = queue.Dequeue(cts.Token); AssertEx.ThrowsExceptionAsync<OperationCanceledException>(task).GetAwaiter().GetResult(); Assert.IsTrue(task.IsCanceled); Assert.IsTrue(queue.IsEmpty(none).ResultEx()); }
public void Cancelled_Dequeue() { var queue = new WaitQueue<int>(); var cts = new CancellationTokenSource(); var task0 = queue.Dequeue(cts.Token); Task.Run(async () => { // wait until dequeue request gets on waitlist while (queue.WaitCount == 0) await Task.Delay(10); Assert.AreEqual<int>(1, queue.WaitCount); }).GetAwaiter().GetResult(); cts.Cancel(); AssertEx.ThrowsExceptionAsync<OperationCanceledException>(task0).GetAwaiter().GetResult(); var isEmpty = queue.IsEmpty(none).GetAwaiter().GetResult(); Assert.IsTrue(isEmpty); }