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