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