mirror of https://github.com/vacp2p/nim-libp2p.git
add missing test
This commit is contained in:
parent
9b20dbc7ae
commit
6ce2782e5c
|
@ -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():
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue