From 6ce2782e5c58728ffcad8ccb956dce89360e6258 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 4 Sep 2019 00:51:16 -0600 Subject: [PATCH] add missing test --- libp2p/muxers/mplex/channel.nim | 6 +++--- tests/testmplex.nim | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libp2p/muxers/mplex/channel.nim b/libp2p/muxers/mplex/channel.nim index b789d4be2..08eba9e40 100644 --- a/libp2p/muxers/mplex/channel.nim +++ b/libp2p/muxers/mplex/channel.nim @@ -68,12 +68,12 @@ proc reset*(s: Channel) {.async.} = await allFutures(s.resetMessage(), s.remoteReset()) proc isReadEof(s: Channel): bool = - bool((s.closedRemote or s.closedLocal) and s.len() <= 0) + bool((s.closedRemote or s.closedLocal) and s.len() < 1) -method pushTo*(s: Channel, data: seq[byte]): Future[void] {.gcsafe.} = +proc pushTo*(s: Channel, data: seq[byte]): Future[void] {.gcsafe.} = if s.closedRemote: raise newLPStreamClosedError() - result = procCall pushTo(BufferStream(s), data) + result = procCall pushTo(BufferStream(s), data) method read*(s: Channel, n = -1): Future[seq[byte]] {.gcsafe.} = if s.isReadEof(): diff --git a/tests/testmplex.nim b/tests/testmplex.nim index 7cbdbbcdc..67ba3a667 100644 --- a/tests/testmplex.nim +++ b/tests/testmplex.nim @@ -178,3 +178,12 @@ suite "Mplex": expect LPStreamClosedError: waitFor(testResetWrite()) + + test "should not allow pushing data to channel when remote end closed": + proc testResetWrite(): Future[void] {.async.} = + let chann = newChannel(1, newConnection(new LPStream), true) + await chann.closeRemote() + await chann.pushTo(@[byte(1)]) + + expect LPStreamClosedError: + waitFor(testResetWrite())