mirror of
https://github.com/logos-storage/nim-libp2p.git
synced 2026-01-05 23:23:12 +00:00
add missing mplex half closed test (#326)
This commit is contained in:
parent
b76b3e0e9b
commit
d1f1e1b31e
@ -77,7 +77,7 @@ method initStream*(s: Connection) =
|
|||||||
s.timeoutHandler = proc() {.async.} =
|
s.timeoutHandler = proc() {.async.} =
|
||||||
await s.close()
|
await s.close()
|
||||||
|
|
||||||
trace "timeout", timeout = $s.timeout.millis
|
trace "timeout set at", timeout = $s.timeout.millis
|
||||||
doAssert(isNil(s.timerTaskFut))
|
doAssert(isNil(s.timerTaskFut))
|
||||||
# doAssert(s.timeout > 0.millis)
|
# doAssert(s.timeout > 0.millis)
|
||||||
if s.timeout > 0.millis:
|
if s.timeout > 0.millis:
|
||||||
|
|||||||
@ -112,7 +112,7 @@ suite "Mplex":
|
|||||||
|
|
||||||
waitFor(testDecodeHeader())
|
waitFor(testDecodeHeader())
|
||||||
|
|
||||||
test "half closed - channel should close for write":
|
test "half closed (local close) - should close for write":
|
||||||
proc testClosedForWrite(): Future[bool] {.async.} =
|
proc testClosedForWrite(): Future[bool] {.async.} =
|
||||||
proc writeHandler(data: seq[byte]) {.async, gcsafe.} = discard
|
proc writeHandler(data: seq[byte]) {.async, gcsafe.} = discard
|
||||||
let
|
let
|
||||||
@ -130,7 +130,40 @@ suite "Mplex":
|
|||||||
check:
|
check:
|
||||||
waitFor(testClosedForWrite()) == true
|
waitFor(testClosedForWrite()) == true
|
||||||
|
|
||||||
test "half closed - channel should close for read by remote":
|
test "half closed (local close) - should allow reads until remote closes":
|
||||||
|
proc testOpenForRead(): Future[bool] {.async.} =
|
||||||
|
let
|
||||||
|
conn = newBufferStream(
|
||||||
|
proc (data: seq[byte]) {.gcsafe, async.} =
|
||||||
|
discard,
|
||||||
|
timeout = 5.minutes
|
||||||
|
)
|
||||||
|
chann = LPChannel.init(1, conn, true)
|
||||||
|
|
||||||
|
await chann.pushTo(("Hello!").toBytes)
|
||||||
|
|
||||||
|
var data = newSeq[byte](6)
|
||||||
|
await chann.close() # closing channel
|
||||||
|
# should be able to read on local clsoe
|
||||||
|
await chann.readExactly(addr data[0], 3)
|
||||||
|
# closing remote end
|
||||||
|
let closeFut = chann.closeRemote()
|
||||||
|
# should still allow reading until buffer EOF
|
||||||
|
await chann.readExactly(addr data[3], 3)
|
||||||
|
await closeFut
|
||||||
|
try:
|
||||||
|
# this should fail now
|
||||||
|
await chann.readExactly(addr data[0], 3)
|
||||||
|
except LPStreamEOFError:
|
||||||
|
result = true
|
||||||
|
finally:
|
||||||
|
await chann.close()
|
||||||
|
await conn.close()
|
||||||
|
|
||||||
|
check:
|
||||||
|
waitFor(testOpenForRead()) == true
|
||||||
|
|
||||||
|
test "half closed (remote close) - channel should close for reading by remote":
|
||||||
proc testClosedForRead(): Future[bool] {.async.} =
|
proc testClosedForRead(): Future[bool] {.async.} =
|
||||||
let
|
let
|
||||||
conn = newBufferStream(
|
conn = newBufferStream(
|
||||||
@ -158,7 +191,7 @@ suite "Mplex":
|
|||||||
check:
|
check:
|
||||||
waitFor(testClosedForRead()) == true
|
waitFor(testClosedForRead()) == true
|
||||||
|
|
||||||
test "half closed - channel should allow writting on remote close":
|
test "half closed (remote close) - channel should allow writting on remote close":
|
||||||
proc testClosedForRead(): Future[bool] {.async.} =
|
proc testClosedForRead(): Future[bool] {.async.} =
|
||||||
let
|
let
|
||||||
testData = "Hello!".toBytes
|
testData = "Hello!".toBytes
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user