From 454571f943b9047b79038cc8d24ad4ae8a8e40e7 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Wed, 8 May 2019 12:44:00 +0300 Subject: [PATCH] Fix tests to consume all the bytes from the nested stream. Add error messages for nested exceptions. --- chronos/streams/asyncstream.nim | 2 ++ tests/testasyncstream.nim | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/chronos/streams/asyncstream.nim b/chronos/streams/asyncstream.nim index dc64e9b..0bfff67 100644 --- a/chronos/streams/asyncstream.nim +++ b/chronos/streams/asyncstream.nim @@ -153,11 +153,13 @@ template toBufferOpenArray*(sb: AsyncBuffer): auto = proc newAsyncStreamReadError(p: ref Exception): ref Exception {.inline.} = var w = newException(AsyncStreamReadError, "Read stream failed") + w.msg = w.msg & ", originated from [" & $p.name & "] " & p.msg w.par = p result = w proc newAsyncStreamWriteError(p: ref Exception): ref Exception {.inline.} = var w = newException(AsyncStreamWriteError, "Write stream failed") + w.msg = w.msg & ", originated from [" & $p.name & "] " & p.msg w.par = p result = w diff --git a/tests/testasyncstream.nim b/tests/testasyncstream.nim index be40a4b..c6dee9f 100644 --- a/tests/testasyncstream.nim +++ b/tests/testasyncstream.nim @@ -199,6 +199,14 @@ suite "AsyncStream test suite": check cast[string](buffer) == "1111111111" await rstream2.readExactly(addr buffer[0], 10) check cast[string](buffer) == "2222222222" + + # We need to consume all the stream with finish markers, but there will + # be no actual data. + let left = await rstream2.consume() + check: + left == 0 + rstream2.atEof() == true + await rstream2.closeWait() await rstream.closeWait() await transp.closeWait() @@ -248,6 +256,14 @@ suite "AsyncStream test suite": check: r3 == 13 cast[string](buffer) == "2222222222NNz" + + # We need to consume all the stream with finish markers, but there will + # be no actual data. + let left = await rstream2.consume() + check: + left == 0 + rstream2.atEof() == true + await rstream2.closeWait() await rstream.closeWait() await transp.closeWait() @@ -285,6 +301,14 @@ suite "AsyncStream test suite": check r2 == "1111111111" var r3 = await rstream2.readLine() check r3 == "2222222222" + + # We need to consume all the stream with finish markers, but there will + # be no actual data. + let left = await rstream2.consume() + check: + left == 0 + rstream2.atEof() == true + await rstream2.closeWait() await rstream.closeWait() await transp.closeWait() @@ -319,6 +343,11 @@ suite "AsyncStream test suite": check cast[string](buf1) == "0000000000" var buf2 = await rstream2.read() check cast[string](buf2) == "11111111112222222222" + + # read() call will consume all the bytes and finish markers too, so + # we just check stream for EOF. + check rstream2.atEof() == true + await rstream2.closeWait() await rstream.closeWait() await transp.closeWait() @@ -370,6 +399,14 @@ suite "AsyncStream test suite": res2 == 10 var buf2 = await rstream2.read(10) check cast[string](buf2) == "3333333333" + + # We need to consume all the stream with finish markers, but there will + # be no actual data. + let left = await rstream2.consume() + check: + left == 0 + rstream2.atEof() == true + await rstream2.closeWait() await rstream.closeWait() await transp.closeWait()