Fix max size write mplex test
This commit is contained in:
parent
cf5dd27e57
commit
ea0d167285
|
@ -15,7 +15,7 @@ import peerinfo,
|
||||||
varint,
|
varint,
|
||||||
vbuffer
|
vbuffer
|
||||||
|
|
||||||
const DefaultReadSize*: uint = 64 * 1024
|
const DefaultReadSize*: uint = 1 shl 20 # 1mb, in order to fit mplex spec
|
||||||
|
|
||||||
type
|
type
|
||||||
Connection* = ref object of LPStream
|
Connection* = ref object of LPStream
|
||||||
|
|
|
@ -113,7 +113,7 @@ method handle*(m: Mplex) {.async, gcsafe.} =
|
||||||
size = data.len
|
size = data.len
|
||||||
|
|
||||||
if data.len > MaxMsgSize:
|
if data.len > MaxMsgSize:
|
||||||
raise newLPStreamLimitError();
|
raise newLPStreamLimitError();
|
||||||
await channel.pushTo(data)
|
await channel.pushTo(data)
|
||||||
of MessageType.CloseIn, MessageType.CloseOut:
|
of MessageType.CloseIn, MessageType.CloseOut:
|
||||||
trace "closing channel", id = id,
|
trace "closing channel", id = id,
|
||||||
|
|
|
@ -187,9 +187,11 @@ suite "Mplex":
|
||||||
|
|
||||||
proc connHandler(conn: Connection) {.async, gcsafe.} =
|
proc connHandler(conn: Connection) {.async, gcsafe.} =
|
||||||
proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
|
proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
|
||||||
|
defer:
|
||||||
|
await stream.close()
|
||||||
let msg = await stream.readLp()
|
let msg = await stream.readLp()
|
||||||
check cast[string](msg) == "Hello from stream!"
|
# we should not reach this anyway!!
|
||||||
await stream.close()
|
check false
|
||||||
listenJob.complete()
|
listenJob.complete()
|
||||||
|
|
||||||
let mplexListen = newMplex(conn)
|
let mplexListen = newMplex(conn)
|
||||||
|
@ -198,9 +200,13 @@ suite "Mplex":
|
||||||
|
|
||||||
let transport1: TcpTransport = newTransport(TcpTransport)
|
let transport1: TcpTransport = newTransport(TcpTransport)
|
||||||
discard await transport1.listen(ma, connHandler)
|
discard await transport1.listen(ma, connHandler)
|
||||||
|
defer:
|
||||||
|
await transport1.close()
|
||||||
|
|
||||||
let transport2: TcpTransport = newTransport(TcpTransport)
|
let transport2: TcpTransport = newTransport(TcpTransport)
|
||||||
let conn = await transport2.dial(transport1.ma)
|
let conn = await transport2.dial(transport1.ma)
|
||||||
|
defer:
|
||||||
|
await conn.close()
|
||||||
|
|
||||||
let mplexDial = newMplex(conn)
|
let mplexDial = newMplex(conn)
|
||||||
let stream = await mplexDial.newStream()
|
let stream = await mplexDial.newStream()
|
||||||
|
@ -208,8 +214,11 @@ suite "Mplex":
|
||||||
for _ in 0..<MaxMsgSize:
|
for _ in 0..<MaxMsgSize:
|
||||||
bigseq.add(uint8(rand(uint('A')..uint('z'))))
|
bigseq.add(uint8(rand(uint('A')..uint('z'))))
|
||||||
await stream.writeLp(bigseq)
|
await stream.writeLp(bigseq)
|
||||||
await conn.close()
|
try:
|
||||||
await listenJob.wait(seconds(5))
|
await listenJob.wait(seconds(5))
|
||||||
|
except AsyncTimeoutError:
|
||||||
|
# we want to time out here!
|
||||||
|
discard
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
|
Loading…
Reference in New Issue