Improve wait() test.
This commit is contained in:
parent
25ad1e2f32
commit
f4803c61ae
|
@ -28,56 +28,56 @@ proc testFuture4(): Future[int] {.async.} =
|
|||
result = 0
|
||||
|
||||
if result == 0:
|
||||
return
|
||||
return -1
|
||||
|
||||
## Test for immediately completed future and timeout = -1
|
||||
result = 0
|
||||
try:
|
||||
var res = await wait(testFuture2(), -1)
|
||||
result = 1
|
||||
result = 2
|
||||
except:
|
||||
result = 0
|
||||
|
||||
if result == 0:
|
||||
return
|
||||
return -2
|
||||
|
||||
## Test for not immediately completed future and timeout = 0
|
||||
result = 0
|
||||
try:
|
||||
var res = await wait(testFuture1(), 0)
|
||||
except AsyncTimeoutError:
|
||||
result = 1
|
||||
result = 3
|
||||
|
||||
if result == 0:
|
||||
return
|
||||
return -3
|
||||
|
||||
## Test for immediately completed future and timeout = 0
|
||||
result = 0
|
||||
try:
|
||||
var res = await wait(testFuture2(), 0)
|
||||
result = 1
|
||||
result = 4
|
||||
except:
|
||||
result = 0
|
||||
|
||||
if result == 0:
|
||||
return
|
||||
return -4
|
||||
|
||||
## Test for future which cannot be completed in timeout period
|
||||
result = 0
|
||||
try:
|
||||
var res = await wait(testFuture1(), 50)
|
||||
except AsyncTimeoutError:
|
||||
result = 1
|
||||
result = 5
|
||||
|
||||
if result == 0:
|
||||
return
|
||||
return -5
|
||||
|
||||
## Test for future which will be completed before timeout exceeded.
|
||||
try:
|
||||
var res = await wait(testFuture1(), 150)
|
||||
result = 1
|
||||
result = 6
|
||||
except:
|
||||
result = 0
|
||||
result = -6
|
||||
|
||||
proc test1(): bool =
|
||||
var fut = testFuture1()
|
||||
|
@ -131,10 +131,8 @@ proc test4(): string =
|
|||
if fut.finished:
|
||||
result = testResult
|
||||
|
||||
proc test5(): bool =
|
||||
var res = waitFor(testFuture4())
|
||||
if res == 1:
|
||||
result = true
|
||||
proc test5(): int =
|
||||
result = waitFor(testFuture4())
|
||||
|
||||
when isMainModule:
|
||||
suite "Future[T] behavior test suite":
|
||||
|
@ -147,4 +145,4 @@ when isMainModule:
|
|||
test "Future[T] callbacks not changing order after removeCallback()":
|
||||
check test4() == "1245"
|
||||
test "wait[T]() test":
|
||||
check test5() == true
|
||||
check test5() == 6
|
||||
|
|
Loading…
Reference in New Issue