Fix max size write mplex test

This commit is contained in:
Giovanni Petrantoni 2020-02-11 14:48:52 +09:00 committed by Dmitriy Ryajov
parent cf5dd27e57
commit ea0d167285
3 changed files with 15 additions and 6 deletions

View File

@ -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

View File

@ -187,9 +187,11 @@ suite "Mplex":
proc connHandler(conn: Connection) {.async, gcsafe.} =
proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
let msg = await stream.readLp()
check cast[string](msg) == "Hello from stream!"
defer:
await stream.close()
let msg = await stream.readLp()
# 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..<MaxMsgSize:
bigseq.add(uint8(rand(uint('A')..uint('z'))))
await stream.writeLp(bigseq)
await conn.close()
try:
await listenJob.wait(seconds(5))
except AsyncTimeoutError:
# we want to time out here!
discard
result = true
check: