From ea0d167285fe3767d3a10a76017551525195ff9f Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Tue, 11 Feb 2020 14:48:52 +0900 Subject: [PATCH] Fix max size write mplex test --- libp2p/connection.nim | 2 +- libp2p/muxers/mplex/mplex.nim | 2 +- tests/testmplex.nim | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libp2p/connection.nim b/libp2p/connection.nim index aaa2815..ae47d04 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -15,7 +15,7 @@ import peerinfo, varint, vbuffer -const DefaultReadSize*: uint = 64 * 1024 +const DefaultReadSize*: uint = 1 shl 20 # 1mb, in order to fit mplex spec type Connection* = ref object of LPStream diff --git a/libp2p/muxers/mplex/mplex.nim b/libp2p/muxers/mplex/mplex.nim index 2d4c7ac..b2b6105 100644 --- a/libp2p/muxers/mplex/mplex.nim +++ b/libp2p/muxers/mplex/mplex.nim @@ -113,7 +113,7 @@ method handle*(m: Mplex) {.async, gcsafe.} = size = data.len if data.len > MaxMsgSize: - raise newLPStreamLimitError(); + raise newLPStreamLimitError(); await channel.pushTo(data) of MessageType.CloseIn, MessageType.CloseOut: trace "closing channel", id = id, diff --git a/tests/testmplex.nim b/tests/testmplex.nim index f88e6f9..49b1001 100644 --- a/tests/testmplex.nim +++ b/tests/testmplex.nim @@ -187,9 +187,11 @@ suite "Mplex": proc connHandler(conn: Connection) {.async, gcsafe.} = proc handleMplexListen(stream: Connection) {.async, gcsafe.} = + defer: + await stream.close() let msg = await stream.readLp() - check cast[string](msg) == "Hello from stream!" - await stream.close() + # we should not reach this anyway!! + check false listenJob.complete() let mplexListen = newMplex(conn) @@ -198,9 +200,13 @@ suite "Mplex": let transport1: TcpTransport = newTransport(TcpTransport) discard await transport1.listen(ma, connHandler) + defer: + await transport1.close() let transport2: TcpTransport = newTransport(TcpTransport) let conn = await transport2.dial(transport1.ma) + defer: + await conn.close() let mplexDial = newMplex(conn) let stream = await mplexDial.newStream() @@ -208,8 +214,11 @@ suite "Mplex": for _ in 0..