mirror of
https://github.com/status-im/nim-chronos.git
synced 2025-01-22 17:29:24 +00:00
More tests added.
This commit is contained in:
parent
a4528ab705
commit
9e63caf694
@ -522,7 +522,7 @@ else:
|
|||||||
let customSet = {Event.Timer, Event.Signal, Event.Process,
|
let customSet = {Event.Timer, Event.Signal, Event.Process,
|
||||||
Event.Vnode}
|
Event.Vnode}
|
||||||
|
|
||||||
# Moving expired timers to `loop.callbacks` and calculate timeout
|
# Moving expired timers to `loop.callbacks` and calculate timeout.
|
||||||
var count = len(loop.timers)
|
var count = len(loop.timers)
|
||||||
if count > 0:
|
if count > 0:
|
||||||
var lastFinish = curTime
|
var lastFinish = curTime
|
||||||
@ -542,6 +542,7 @@ else:
|
|||||||
if len(loop.callbacks) != 0:
|
if len(loop.callbacks) != 0:
|
||||||
curTimeout = 0
|
curTimeout = 0
|
||||||
|
|
||||||
|
# Processing IO descriptors and all hardware events.
|
||||||
count = loop.selector.selectInto(curTimeout, loop.keys)
|
count = loop.selector.selectInto(curTimeout, loop.keys)
|
||||||
for i in 0..<count:
|
for i in 0..<count:
|
||||||
let fd = loop.keys[i].fd
|
let fd = loop.keys[i].fd
|
||||||
@ -574,7 +575,8 @@ else:
|
|||||||
loop.callbacks.addLast(loop.timers.pop().function)
|
loop.callbacks.addLast(loop.timers.pop().function)
|
||||||
dec(count)
|
dec(count)
|
||||||
|
|
||||||
# All callbacks which will be added in process will be processed on next
|
# Scheduling callbacks.
|
||||||
|
# all callbacks which will be added in process will be processed on next
|
||||||
# poll() call.
|
# poll() call.
|
||||||
count = len(loop.callbacks)
|
count = len(loop.callbacks)
|
||||||
for i in 0..<count:
|
for i in 0..<count:
|
||||||
|
@ -33,7 +33,7 @@ proc test2(): bool =
|
|||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
suite "Future[T] behavior test suite":
|
suite "Future[T] behavior test suite":
|
||||||
test "sleepAsync() test":
|
test "`Async undefined behavior (#7758)` test":
|
||||||
check test1() == true
|
check test1() == true
|
||||||
test "Immediately completed asynchronous procedure test":
|
test "Immediately completed asynchronous procedure test":
|
||||||
check test2() == true
|
check test2() == true
|
||||||
|
@ -13,6 +13,7 @@ const CallSoonTests = 10
|
|||||||
var soonTest1 = 0'u
|
var soonTest1 = 0'u
|
||||||
var timeoutsTest1 = 0
|
var timeoutsTest1 = 0
|
||||||
var timeoutsTest2 = 0
|
var timeoutsTest2 = 0
|
||||||
|
var soonTest2 = 0
|
||||||
|
|
||||||
proc callback1(udata: pointer) {.gcsafe.} =
|
proc callback1(udata: pointer) {.gcsafe.} =
|
||||||
soonTest1 = soonTest1 xor cast[uint](udata)
|
soonTest1 = soonTest1 xor cast[uint](udata)
|
||||||
@ -53,6 +54,14 @@ proc test2(timers, callbacks: var int) =
|
|||||||
timers = timeoutsTest1
|
timers = timeoutsTest1
|
||||||
callbacks = timeoutsTest2
|
callbacks = timeoutsTest2
|
||||||
|
|
||||||
|
proc testCallback(udata: pointer) =
|
||||||
|
soonTest2 = 987654321
|
||||||
|
|
||||||
|
proc test3(): bool =
|
||||||
|
callSoon(testCallback)
|
||||||
|
poll()
|
||||||
|
result = soonTest2 == 987654321
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
suite "callSoon() tests suite":
|
suite "callSoon() tests suite":
|
||||||
test "User-defined callback argument test":
|
test "User-defined callback argument test":
|
||||||
@ -64,9 +73,11 @@ when isMainModule:
|
|||||||
for item in values:
|
for item in values:
|
||||||
expect = expect xor item
|
expect = expect xor item
|
||||||
check test1() == expect
|
check test1() == expect
|
||||||
test "callSoon() behavior test":
|
test "`Asynchronous dead end` #7193 test":
|
||||||
var timers, callbacks: int
|
var timers, callbacks: int
|
||||||
test2(timers, callbacks)
|
test2(timers, callbacks)
|
||||||
check:
|
check:
|
||||||
timers == CallSoonTests
|
timers == CallSoonTests
|
||||||
callbacks > CallSoonTests * 2
|
callbacks > CallSoonTests * 2
|
||||||
|
test "`callSoon() is not working prior getGlobalDispatcher()` #7192 test":
|
||||||
|
check test3() == true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user