More tests added.

This commit is contained in:
cheatfate 2018-05-25 23:00:32 +03:00
parent a4528ab705
commit 9e63caf694
3 changed files with 17 additions and 4 deletions

View File

@ -522,7 +522,7 @@ else:
let customSet = {Event.Timer, Event.Signal, Event.Process,
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)
if count > 0:
var lastFinish = curTime
@ -542,6 +542,7 @@ else:
if len(loop.callbacks) != 0:
curTimeout = 0
# Processing IO descriptors and all hardware events.
count = loop.selector.selectInto(curTimeout, loop.keys)
for i in 0..<count:
let fd = loop.keys[i].fd
@ -574,7 +575,8 @@ else:
loop.callbacks.addLast(loop.timers.pop().function)
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.
count = len(loop.callbacks)
for i in 0..<count:

View File

@ -33,7 +33,7 @@ proc test2(): bool =
when isMainModule:
suite "Future[T] behavior test suite":
test "sleepAsync() test":
test "`Async undefined behavior (#7758)` test":
check test1() == true
test "Immediately completed asynchronous procedure test":
check test2() == true

View File

@ -13,6 +13,7 @@ const CallSoonTests = 10
var soonTest1 = 0'u
var timeoutsTest1 = 0
var timeoutsTest2 = 0
var soonTest2 = 0
proc callback1(udata: pointer) {.gcsafe.} =
soonTest1 = soonTest1 xor cast[uint](udata)
@ -53,6 +54,14 @@ proc test2(timers, callbacks: var int) =
timers = timeoutsTest1
callbacks = timeoutsTest2
proc testCallback(udata: pointer) =
soonTest2 = 987654321
proc test3(): bool =
callSoon(testCallback)
poll()
result = soonTest2 == 987654321
when isMainModule:
suite "callSoon() tests suite":
test "User-defined callback argument test":
@ -64,9 +73,11 @@ when isMainModule:
for item in values:
expect = expect xor item
check test1() == expect
test "callSoon() behavior test":
test "`Asynchronous dead end` #7193 test":
var timers, callbacks: int
test2(timers, callbacks)
check:
timers == CallSoonTests
callbacks > CallSoonTests * 2
test "`callSoon() is not working prior getGlobalDispatcher()` #7192 test":
check test3() == true