From ac8b11d6ca663e9409adb671ee51515e9d524c23 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Wed, 20 Jan 2021 17:08:16 +0200 Subject: [PATCH] close() procedure should not raise, otherwise its impossible to cleanup. --- chronos/streams/boundstream.nim | 24 ------------------------ tests/testasyncstream.nim | 29 ----------------------------- 2 files changed, 53 deletions(-) diff --git a/chronos/streams/boundstream.nim b/chronos/streams/boundstream.nim index 0136a86b..542c187d 100644 --- a/chronos/streams/boundstream.nim +++ b/chronos/streams/boundstream.nim @@ -186,27 +186,3 @@ proc newBoundedStreamWriter*(wsource: AsyncStreamWriter, var res = BoundedStreamWriter(boundSize: boundSize) res.init(wsource, queueSize) res - -proc close*(rw: BoundedStreamRW) = - ## Close and frees resources of stream ``rw``. - ## - ## Note close() procedure is not completed immediately. - if rw.closed(): - raise newAsyncStreamIncorrectError("Stream is already closed!") - # We do not want to raise one more IncompleteError if it was already raised - # by one of the read()/write() primitives. - if rw.state != AsyncStreamState.Error: - if rw.bytesLeft() != 0'u64: - raise newBoundedStreamIncompleteError() - when rw is BoundedStreamReader: - cast[AsyncStreamReader](rw).close() - elif rw is BoundedStreamWriter: - cast[AsyncStreamWriter](rw).close() - -proc closeWait*(rw: BoundedStreamRW): Future[void] = - ## Close and frees resources of stream ``rw``. - rw.close() - when rw is BoundedStreamReader: - cast[AsyncStreamReader](rw).join() - elif rw is BoundedStreamWriter: - cast[AsyncStreamWriter](rw).join() diff --git a/tests/testasyncstream.nim b/tests/testasyncstream.nim index 13b426c0..61138341 100644 --- a/tests/testasyncstream.nim +++ b/tests/testasyncstream.nim @@ -715,19 +715,6 @@ suite "BoundedStream test suite": except BoundedStreamIncompleteError: clientRes = true await wbstream.closeWait() - elif test == 3: - for i in 0 ..< 10: - await wbstream.write(messagePart) - await wbstream.finish() - await wbstream.closeWait() - clientRes = true - elif test == 4: - for i in 0 ..< 9: - await wbstream.write(messagePart) - try: - await wbstream.closeWait() - except BoundedStreamIncompleteError: - clientRes = true await wstream.closeWait() await transp.closeWait() @@ -755,18 +742,6 @@ suite "BoundedStream test suite": except BoundedStreamIncompleteError: res = true await rbstream.closeWait() - elif test == 3: - let response {.used.} = await rbstream.read(int(size) - 1) - try: - await rbstream.closeWait() - except BoundedStreamIncompleteError: - res = true - elif test == 4: - try: - let response {.used.} = await rbstream.read() - except BoundedStreamIncompleteError: - res = true - await rbstream.closeWait() await rstream.closeWait() await conn.closeWait() @@ -780,7 +755,3 @@ suite "BoundedStream test suite": check waitFor(boundedTest(address, 1, item)) == true test "BoundedStream incomplete test [" & $item & "]": check waitFor(boundedTest(address, 2, item)) == true - test "BoundedStream read() close test [" & $item & "]": - check waitFor(boundedTest(address, 3, item)) == true - test "BoundedStream write() close test [" & $item & "]": - check waitFor(boundedTest(address, 4, item)) == true