Add more tests.

This commit is contained in:
bhartnett 2024-10-03 21:36:24 +08:00
parent 522530ee9a
commit 428c2b948c
No known key found for this signature in database
GPG Key ID: 076F2830DA6BD535
1 changed files with 38 additions and 0 deletions

View File

@ -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()