From 428c2b948ce56c32c4b8235f9e00f9b117a2473c Mon Sep 17 00:00:00 2001 From: bhartnett <51288821+bhartnett@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:36:24 +0800 Subject: [PATCH] Add more tests. --- tests/testsync.nim | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/testsync.nim b/tests/testsync.nim index 56e2dca6..85dd19a6 100644 --- a/tests/testsync.nim +++ b/tests/testsync.nim @@ -366,6 +366,44 @@ suite "Asynchronous sync primitives test suite": (waitFor q.peekFirst()) == 1 (waitFor q.peekLast()) == 2 + test "AsyncQueue() peek before pop test": + let q = newAsyncQueue[int]() + q.putNoWait(1) + + let + a = q.peekFirst() + b = q.popFirst() + + check: + a.completed() == true + b.completed() == true + a.read() == 1 + b.read() == 1 + q.len() == 0 + + test "AsyncQueue() peek after pop test": + let q = newAsyncQueue[int]() + q.putNoWait(1) + + let + a = q.popFirst() + b = q.peekFirst() + + check: + a.completed() == true + b.completed() == false + a.read() == 1 + q.len() == 0 + + q.putNoWait(2) + poll() + + check: + a.completed() == true + b.completed() == true + b.read() == 2 + q.len() == 1 + test "AsyncEventQueue() behavior test": let eventQueue = newAsyncEventQueue[int]() let key = eventQueue.register()