diff options
Diffstat (limited to 'tests/async/tupcoming_async.nim')
-rw-r--r-- | tests/async/tupcoming_async.nim | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/tests/async/tupcoming_async.nim b/tests/async/tupcoming_async.nim index 137794afd..7d255f213 100644 --- a/tests/async/tupcoming_async.nim +++ b/tests/async/tupcoming_async.nim @@ -8,11 +8,12 @@ OK """ when defined(upcoming): - import asyncdispatch, times, osproc, streams + import asyncdispatch, times, streams, posix + from ioselectors import ioselSupportedPlatform - const supportedPlatform = defined(linux) or defined(freebsd) or - defined(netbsd) or defined(openbsd) or - defined(macosx) + proc delayedSet(ev: AsyncEvent, timeout: int): Future[void] {.async.} = + await sleepAsync(timeout) + ev.setEvent() proc waitEvent(ev: AsyncEvent, closeEvent = false): Future[void] = var retFuture = newFuture[void]("waitEvent") @@ -25,56 +26,55 @@ when defined(upcoming): addEvent(ev, cb) return retFuture - proc waitTimer(timeout: int): Future[void] = - var retFuture = newFuture[void]("waitTimer") - proc cb(fd: AsyncFD): bool = - retFuture.complete() - addTimer(timeout, true, cb) - return retFuture - - proc waitProcess(p: Process): Future[void] = - var retFuture = newFuture[void]("waitProcess") - proc cb(fd: AsyncFD): bool = - retFuture.complete() - addProcess(p.processID(), cb) - return retFuture - - proc delayedSet(ev: AsyncEvent, timeout: int): Future[void] {.async.} = - await waitTimer(timeout) - ev.setEvent() - - proc timerTest() = - waitFor(waitTimer(200)) - echo "OK" - proc eventTest() = var event = newAsyncEvent() var fut = waitEvent(event) asyncCheck(delayedSet(event, 500)) - waitFor(fut or waitTimer(1000)) + waitFor(fut or sleepAsync(1000)) if fut.finished: echo "OK" else: echo "eventTest: Timeout expired before event received!" - proc processTest() = - when defined(windows): - var process = startProcess("ping.exe", "", - ["127.0.0.1", "-n", "2", "-w", "100"], nil, - {poStdErrToStdOut, poUsePath, poInteractive, - poDemon}) - else: - var process = startProcess("/bin/sleep", "", ["1"], nil, - {poStdErrToStdOut, poUsePath}) - var fut = waitProcess(process) - waitFor(fut or waitTimer(2000)) - if fut.finished and process.peekExitCode() == 0: + when ioselSupportedPlatform or defined(windows): + + import osproc + + proc waitTimer(timeout: int): Future[void] = + var retFuture = newFuture[void]("waitTimer") + proc cb(fd: AsyncFD): bool = + retFuture.complete() + addTimer(timeout, true, cb) + return retFuture + + proc waitProcess(p: Process): Future[void] = + var retFuture = newFuture[void]("waitProcess") + proc cb(fd: AsyncFD): bool = + retFuture.complete() + addProcess(p.processID(), cb) + return retFuture + + proc timerTest() = + waitFor(waitTimer(200)) echo "OK" - else: - echo "processTest: Timeout expired before process exited!" - when supportedPlatform: - import posix + proc processTest() = + when defined(windows): + var process = startProcess("ping.exe", "", + ["127.0.0.1", "-n", "2", "-w", "100"], nil, + {poStdErrToStdOut, poUsePath, poInteractive, + poDemon}) + else: + var process = startProcess("/bin/sleep", "", ["1"], nil, + {poStdErrToStdOut, poUsePath}) + var fut = waitProcess(process) + waitFor(fut or waitTimer(2000)) + if fut.finished and process.peekExitCode() == 0: + echo "OK" + else: + echo "processTest: Timeout expired before process exited!" + + when ioselSupportedPlatform: proc waitSignal(signal: int): Future[void] = var retFuture = newFuture[void]("waitSignal") @@ -97,7 +97,7 @@ when defined(upcoming): else: echo "signalTest: Timeout expired before signal received!" - when supportedPlatform: + when ioselSupportedPlatform: timerTest() eventTest() processTest() |