diff options
author | Daniil Yarancev <21169548+Yardanico@users.noreply.github.com> | 2018-01-07 21:02:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-07 21:02:00 +0300 |
commit | fb44c522e6173528efa8035ecc459c84887d0167 (patch) | |
tree | a2f5e98606be265981a5f72748896967033e23d7 /tests/async | |
parent | ccf99fa5ce4fe992fb80dc89271faa51456c3fa5 (diff) | |
parent | e23ea64c41e101d4e1d933f0b015f51cc6c2f7de (diff) | |
download | Nim-fb44c522e6173528efa8035ecc459c84887d0167.tar.gz |
Merge pull request #1 from nim-lang/devel
upstream
Diffstat (limited to 'tests/async')
-rw-r--r-- | tests/async/tasync_in_seq_constr.nim | 5 | ||||
-rw-r--r-- | tests/async/tasync_traceback.nim | 116 | ||||
-rw-r--r-- | tests/async/tasyncall.nim | 26 | ||||
-rw-r--r-- | tests/async/tasyncdial.nim | 1 | ||||
-rw-r--r-- | tests/async/tasyncfile.nim | 15 | ||||
-rw-r--r-- | tests/async/tasyncsend4757.nim | 15 | ||||
-rw-r--r-- | tests/async/tioselectors.nim | 8 | ||||
-rw-r--r-- | tests/async/tnewasyncudp.nim | 2 |
8 files changed, 174 insertions, 14 deletions
diff --git a/tests/async/tasync_in_seq_constr.nim b/tests/async/tasync_in_seq_constr.nim index 7d216e352..46ad74451 100644 --- a/tests/async/tasync_in_seq_constr.nim +++ b/tests/async/tasync_in_seq_constr.nim @@ -1,8 +1,9 @@ discard """ - output: '''@[1, 2, 3, 4]''' + errormsg: "invalid control flow: 'yield' within a constructor" + line: 16 """ -# bug #5314 +# bug #5314, bug #6626 import asyncdispatch diff --git a/tests/async/tasync_traceback.nim b/tests/async/tasync_traceback.nim new file mode 100644 index 000000000..08f7e7317 --- /dev/null +++ b/tests/async/tasync_traceback.nim @@ -0,0 +1,116 @@ +discard """ + exitcode: 0 + disabled: "windows" + output: ''' +b failure +Async traceback: + tasync_traceback.nim(97) tasync_traceback + asyncmacro.nim(395) a + asyncmacro.nim(34) a_continue + ## Resumes an async procedure + tasync_traceback.nim(95) aIter + asyncmacro.nim(395) b + asyncmacro.nim(34) b_continue + ## Resumes an async procedure + tasync_traceback.nim(92) bIter + #[ + tasync_traceback.nim(97) tasync_traceback + asyncmacro.nim(395) a + asyncmacro.nim(43) a_continue + ## Resumes an async procedure + asyncfutures.nim(211) callback= + asyncfutures.nim(190) addCallback + asyncfutures.nim(53) callSoon + asyncmacro.nim(34) a_continue + ## Resumes an async procedure + asyncmacro.nim(0) aIter + asyncfutures.nim(304) read + ]# +Exception message: b failure +Exception type: + +bar failure +Async traceback: + tasync_traceback.nim(113) tasync_traceback + asyncdispatch.nim(1492) waitFor + asyncdispatch.nim(1496) poll + ## Processes asynchronous completion events + asyncdispatch.nim(1262) runOnce + asyncdispatch.nim(183) processPendingCallbacks + ## Executes pending callbacks + asyncmacro.nim(34) bar_continue + ## Resumes an async procedure + tasync_traceback.nim(108) barIter + #[ + tasync_traceback.nim(113) tasync_traceback + asyncdispatch.nim(1492) waitFor + asyncdispatch.nim(1496) poll + ## Processes asynchronous completion events + asyncdispatch.nim(1262) runOnce + asyncdispatch.nim(183) processPendingCallbacks + ## Executes pending callbacks + asyncmacro.nim(34) foo_continue + ## Resumes an async procedure + asyncmacro.nim(0) fooIter + asyncfutures.nim(304) read + ]# +Exception message: bar failure +Exception type:''' +""" +import asyncdispatch + +# Tests to ensure our exception trace backs are friendly. + +# --- Simple test. --- +# +# What does this look like when it's synchronous? +# +# tasync_traceback.nim(23) tasync_traceback +# tasync_traceback.nim(21) a +# tasync_traceback.nim(18) b +# Error: unhandled exception: b failure [OSError] +# +# Good (not quite ideal, but gotta work within constraints) traceback, +# when exception is unhandled: +# +# <traceback for the unhandled exception> +# <very much a bunch of noise> +# <would be ideal to customise this> +# <(the code responsible is in excpt:raiseExceptionAux)> +# Error: unhandled exception: b failure +# =============== +# Async traceback +# =============== +# +# tasync_traceback.nim(23) tasync_traceback +# +# tasync_traceback.nim(21) a +# tasync_traceback.nim(18) b + +proc b(): Future[int] {.async.} = + if true: + raise newException(OSError, "b failure") + +proc a(): Future[int] {.async.} = + return await b() + +let aFut = a() +try: + discard waitFor aFut +except Exception as exc: + echo exc.msg +echo() + +# From #6803 +proc bar(): Future[string] {.async.} = + await sleepAsync(100) + if true: + raise newException(OSError, "bar failure") + +proc foo(): Future[string] {.async.} = return await bar() + +try: + echo waitFor(foo()) +except Exception as exc: + echo exc.msg +echo() \ No newline at end of file diff --git a/tests/async/tasyncall.nim b/tests/async/tasyncall.nim index 7daecd9ef..775dd0c6f 100644 --- a/tests/async/tasyncall.nim +++ b/tests/async/tasyncall.nim @@ -40,8 +40,17 @@ proc testVarargs(x, y, z: int): seq[int] = result = waitFor all(a, b, c) -suite "tasyncall": - test "testFuturesWithValue": +proc testWithDupes() = + var + tasks = newSeq[Future[void]](taskCount) + fut = futureWithoutValue() + + for i in 0..<taskCount: + tasks[i] = fut + + waitFor all(tasks) + +block: let startTime = cpuTime() results = testFuturesWithValue(42) @@ -51,14 +60,21 @@ suite "tasyncall": doAssert execTime * 1000 < taskCount * sleepDuration doAssert results == expected - test "testFuturesWithoutValues": +block: let startTime = cpuTime() testFuturesWithoutValues() let execTime = cpuTime() - startTime doAssert execTime * 1000 < taskCount * sleepDuration - test "testVarargs": +block: + let startTime = cpuTime() + testWithDupes() + let execTime = cpuTime() - startTime + + doAssert execTime * 1000 < taskCount * sleepDuration + +block: let startTime = cpuTime() results = testVarargs(1, 2, 3) @@ -68,7 +84,7 @@ suite "tasyncall": doAssert execTime * 100 < taskCount * sleepDuration doAssert results == expected - test "all on seq[Future]": +block: let noIntFuturesFut = all(newSeq[Future[int]]()) noVoidFuturesFut = all(newSeq[Future[void]]()) diff --git a/tests/async/tasyncdial.nim b/tests/async/tasyncdial.nim index d70e14020..fa81235fe 100644 --- a/tests/async/tasyncdial.nim +++ b/tests/async/tasyncdial.nim @@ -4,6 +4,7 @@ discard """ OK AF_INET OK AF_INET6 ''' + disabled: "travis" """ import diff --git a/tests/async/tasyncfile.nim b/tests/async/tasyncfile.nim index 592f0ebd8..6c0725c88 100644 --- a/tests/async/tasyncfile.nim +++ b/tests/async/tasyncfile.nim @@ -34,4 +34,19 @@ proc main() {.async.} = doAssert data == "foot\ntest2" file.close() + # Issue #5531 + block: + removeFile(fn) + var file = openAsync(fn, fmWrite) + await file.write("test2") + file.close() + file = openAsync(fn, fmWrite) + await file.write("test3") + file.close() + file = openAsync(fn, fmRead) + let data = await file.readAll() + doAssert data == "test3" + file.close() + + waitFor main() diff --git a/tests/async/tasyncsend4757.nim b/tests/async/tasyncsend4757.nim index 1066f38e5..752bb3e75 100644 --- a/tests/async/tasyncsend4757.nim +++ b/tests/async/tasyncsend4757.nim @@ -3,11 +3,22 @@ discard """ output: "Finished" """ -import asyncdispatch +import asyncdispatch, asyncnet + +proc createServer(port: Port) {.async.} = + var server = newAsyncSocket() + server.setSockOpt(OptReuseAddr, true) + bindAddr(server, port) + server.listen() + while true: + let client = await server.accept() + discard await client.recvLine() + +asyncCheck createServer(10335.Port) proc f(): Future[void] {.async.} = let s = newAsyncNativeSocket() - await s.connect("example.com", 80.Port) + await s.connect("localhost", 10335.Port) await s.send("123") echo "Finished" diff --git a/tests/async/tioselectors.nim b/tests/async/tioselectors.nim index 034c2185c..d2e4cfec1 100644 --- a/tests/async/tioselectors.nim +++ b/tests/async/tioselectors.nim @@ -2,7 +2,7 @@ discard """ file: "tioselectors.nim" output: "All tests passed!" """ -import ioselectors +import selectors const hasThreadSupport = compileOption("threads") @@ -579,9 +579,9 @@ else: var event = newSelectEvent() selector.registerEvent(event, 1) discard selector.select(0) - event.setEvent() + event.trigger() var rc1 = selector.select(0) - event.setEvent() + event.trigger() var rc2 = selector.select(0) var rc3 = selector.select(0) assert(len(rc1) == 1 and len(rc2) == 1 and len(rc3) == 0) @@ -611,7 +611,7 @@ else: var event = newSelectEvent() for i in 0..high(thr): createThread(thr[i], event_wait_thread, event) - event.setEvent() + event.trigger() joinThreads(thr) assert(counter == 1) result = true diff --git a/tests/async/tnewasyncudp.nim b/tests/async/tnewasyncudp.nim index b56cdc71b..e61f630e4 100644 --- a/tests/async/tnewasyncudp.nim +++ b/tests/async/tnewasyncudp.nim @@ -86,7 +86,7 @@ proc readMessages(server: AsyncFD) {.async.} = size = 0 var grammString = $cstring(addr buffer) if grammString.startswith("Message ") and - saddr.sin_addr.s_addr == 0x100007F: + saddr.sin_addr.s_addr == nativesockets.ntohl(INADDR_LOOPBACK.uint32): await sendTo(server, addr grammString[0], len(grammString), cast[ptr SockAddr](addr saddr), slen) inc(msgCount) |