From f4803c61ae7871ff43ef8e0f5c76d1a095859534 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Tue, 24 Jul 2018 16:55:51 +0300 Subject: [PATCH] Improve wait() test. --- tests/testfut.nim | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/testfut.nim b/tests/testfut.nim index cca43d3b..dbc698e9 100644 --- a/tests/testfut.nim +++ b/tests/testfut.nim @@ -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