bring back commented tests

This commit is contained in:
Dmitriy Ryajov 2019-09-25 16:57:27 -06:00
parent bc46a76029
commit f7e5c8ee30
2 changed files with 115 additions and 115 deletions

View File

@ -58,7 +58,7 @@ method handle*(m: Mplex) {.async, gcsafe.} =
let msgRes = await m.connection.readMsg()
if msgRes.isNone:
# TODO: this should ideally be poll(timeout = 100)
# but chronos poll() doesnt take a timeout, so it
# but chronos poll() doesnt take a timeout, so it
# might and does hang
await sleepAsync(100.millis) # yield to async loop
continue

View File

@ -118,149 +118,149 @@ suite "Mplex":
check:
waitFor(testDecodeHeader()) == true
# test "e2e - read/write receiver":
# proc testNewStream(): Future[bool] {.async.} =
# let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53381")
test "e2e - read/write receiver":
proc testNewStream(): Future[bool] {.async.} =
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
# proc connHandler(conn: Connection) {.async, gcsafe.} =
# proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
# let msg = await stream.readLp()
# check cast[string](msg) == "Hello from stream!"
# await stream.close()
proc connHandler(conn: Connection) {.async, gcsafe.} =
proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
let msg = await stream.readLp()
check cast[string](msg) == "Hello from stream!"
await stream.close()
# let mplexListen = newMplex(conn)
# mplexListen.streamHandler = handleMplexListen
# discard mplexListen.handle()
let mplexListen = newMplex(conn)
mplexListen.streamHandler = handleMplexListen
discard mplexListen.handle()
# let transport1: TcpTransport = newTransport(TcpTransport)
# discard await transport1.listen(ma, connHandler)
let transport1: TcpTransport = newTransport(TcpTransport)
discard await transport1.listen(ma, connHandler)
# let transport2: TcpTransport = newTransport(TcpTransport)
# let conn = await transport2.dial(ma)
let transport2: TcpTransport = newTransport(TcpTransport)
let conn = await transport2.dial(transport1.ma)
# let mplexDial = newMplex(conn)
# let stream = await mplexDial.newStream()
# await stream.writeLp("Hello from stream!")
# await conn.close()
# result = true
let mplexDial = newMplex(conn)
let stream = await mplexDial.newStream()
await stream.writeLp("Hello from stream!")
await conn.close()
result = true
# check:
# waitFor(testNewStream()) == true
check:
waitFor(testNewStream()) == true
# test "e2e - read/write initiator":
# proc testNewStream(): Future[bool] {.async.} =
# let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53380")
test "e2e - read/write initiator":
proc testNewStream(): Future[bool] {.async.} =
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
# proc connHandler(conn: Connection) {.async, gcsafe.} =
# proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
# await stream.writeLp("Hello from stream!")
# await stream.close()
proc connHandler(conn: Connection) {.async, gcsafe.} =
proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
await stream.writeLp("Hello from stream!")
await stream.close()
# let mplexListen = newMplex(conn)
# mplexListen.streamHandler = handleMplexListen
# await mplexListen.handle()
let mplexListen = newMplex(conn)
mplexListen.streamHandler = handleMplexListen
await mplexListen.handle()
# let transport1: TcpTransport = newTransport(TcpTransport)
# discard await transport1.listen(ma, connHandler)
let transport1: TcpTransport = newTransport(TcpTransport)
discard await transport1.listen(ma, connHandler)
# let transport2: TcpTransport = newTransport(TcpTransport)
# let conn = await transport2.dial(ma)
let transport2: TcpTransport = newTransport(TcpTransport)
let conn = await transport2.dial(transport1.ma)
# let mplexDial = newMplex(conn)
# let dialFut = mplexDial.handle()
# let stream = await mplexDial.newStream("DIALER")
# let msg = cast[string](await stream.readLp())
# check msg == "Hello from stream!"
# await conn.close()
# # await dialFut
# result = true
let mplexDial = newMplex(conn)
let dialFut = mplexDial.handle()
let stream = await mplexDial.newStream("DIALER")
let msg = cast[string](await stream.readLp())
check msg == "Hello from stream!"
await conn.close()
# await dialFut
result = true
# check:
# waitFor(testNewStream()) == true
check:
waitFor(testNewStream()) == true
# test "e2e - multiple streams":
# proc testNewStream(): Future[bool] {.async.} =
# let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53382")
test "e2e - multiple streams":
proc testNewStream(): Future[bool] {.async.} =
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
# var count = 1
# var listenConn: Connection
# proc connHandler(conn: Connection) {.async, gcsafe.} =
# proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
# let msg = await stream.readLp()
# check cast[string](msg) == &"stream {count}!"
# count.inc
# await stream.close()
var count = 1
var listenConn: Connection
proc connHandler(conn: Connection) {.async, gcsafe.} =
proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
let msg = await stream.readLp()
check cast[string](msg) == &"stream {count}!"
count.inc
await stream.close()
# listenConn = conn
# let mplexListen = newMplex(conn)
# mplexListen.streamHandler = handleMplexListen
# await mplexListen.handle()
listenConn = conn
let mplexListen = newMplex(conn)
mplexListen.streamHandler = handleMplexListen
await mplexListen.handle()
# let transport1: TcpTransport = newTransport(TcpTransport)
# discard await transport1.listen(ma, connHandler)
let transport1: TcpTransport = newTransport(TcpTransport)
discard await transport1.listen(ma, connHandler)
# let transport2: TcpTransport = newTransport(TcpTransport)
# let conn = await transport2.dial(ma)
let transport2: TcpTransport = newTransport(TcpTransport)
let conn = await transport2.dial(transport1.ma)
# let mplexDial = newMplex(conn)
# for i in 1..<10:
# let stream = await mplexDial.newStream()
# await stream.writeLp(&"stream {i}!")
# await stream.close()
let mplexDial = newMplex(conn)
for i in 1..<10:
let stream = await mplexDial.newStream()
await stream.writeLp(&"stream {i}!")
await stream.close()
# await conn.close()
# await listenConn.close()
# result = true
await conn.close()
await listenConn.close()
result = true
# check:
# waitFor(testNewStream()) == true
check:
waitFor(testNewStream()) == true
# test "e2e - multiple read/write streams":
# proc testNewStream(): Future[bool] {.async.} =
# let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53383")
test "e2e - multiple read/write streams":
proc testNewStream(): Future[bool] {.async.} =
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
# var count = 1
# var listenFut: Future[void]
# var listenConn: Connection
# proc connHandler(conn: Connection) {.async, gcsafe.} =
# listenConn = conn
# proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
# let msg = await stream.readLp()
# check cast[string](msg) == &"stream {count} from dialer!"
# await stream.writeLp(&"stream {count} from listener!")
# count.inc
# await stream.close()
var count = 1
var listenFut: Future[void]
var listenConn: Connection
proc connHandler(conn: Connection) {.async, gcsafe.} =
listenConn = conn
proc handleMplexListen(stream: Connection) {.async, gcsafe.} =
let msg = await stream.readLp()
check cast[string](msg) == &"stream {count} from dialer!"
await stream.writeLp(&"stream {count} from listener!")
count.inc
await stream.close()
# let mplexListen = newMplex(conn)
# mplexListen.streamHandler = handleMplexListen
# listenFut = mplexListen.handle()
# listenFut.addCallback(proc(udata: pointer) {.gcsafe.}
# = debug "completed listener")
let mplexListen = newMplex(conn)
mplexListen.streamHandler = handleMplexListen
listenFut = mplexListen.handle()
listenFut.addCallback(proc(udata: pointer) {.gcsafe.}
= debug "completed listener")
# let transport1: TcpTransport = newTransport(TcpTransport)
# asyncCheck transport1.listen(ma, connHandler)
let transport1: TcpTransport = newTransport(TcpTransport)
asyncCheck transport1.listen(ma, connHandler)
# let transport2: TcpTransport = newTransport(TcpTransport)
# let conn = await transport2.dial(ma)
let transport2: TcpTransport = newTransport(TcpTransport)
let conn = await transport2.dial(transport1.ma)
# let mplexDial = newMplex(conn)
# let dialFut = mplexDial.handle()
# dialFut.addCallback(proc(udata: pointer = nil) {.gcsafe.}
# = debug "completed dialer")
# for i in 1..10:
# let stream = await mplexDial.newStream("dialer stream")
# await stream.writeLp(&"stream {i} from dialer!")
# let msg = await stream.readLp()
# check cast[string](msg) == &"stream {i} from listener!"
# await stream.close()
let mplexDial = newMplex(conn)
let dialFut = mplexDial.handle()
dialFut.addCallback(proc(udata: pointer = nil) {.gcsafe.}
= debug "completed dialer")
for i in 1..10:
let stream = await mplexDial.newStream("dialer stream")
await stream.writeLp(&"stream {i} from dialer!")
let msg = await stream.readLp()
check cast[string](msg) == &"stream {i} from listener!"
await stream.close()
# await conn.close()
# await listenConn.close()
# await allFutures(dialFut, listenFut)
# result = true
await conn.close()
await listenConn.close()
await allFutures(dialFut, listenFut)
result = true
# check:
# waitFor(testNewStream()) == true
check:
waitFor(testNewStream()) == true
test "half closed - channel should close for write":
proc testClosedForWrite(): Future[void] {.async.} =