test connections properly
This commit is contained in:
parent
2febd47e0d
commit
0347a8ef1d
|
@ -183,6 +183,7 @@ suite "Mplex":
|
||||||
let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53382")
|
let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53382")
|
||||||
|
|
||||||
var count = 1
|
var count = 1
|
||||||
|
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()
|
||||||
|
@ -190,9 +191,12 @@ suite "Mplex":
|
||||||
count.inc
|
count.inc
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
listenConn = conn
|
||||||
let mplexListen = newMplex(conn)
|
let mplexListen = newMplex(conn)
|
||||||
mplexListen.streamHandler = handleMplexListen
|
mplexListen.streamHandler = handleMplexListen
|
||||||
asyncCheck mplexListen.handle()
|
mplexListen.handle()
|
||||||
|
.addCallback(proc(udata: pointer) =
|
||||||
|
debug "handle completed")
|
||||||
|
|
||||||
let transport1: TcpTransport = newTransport(TcpTransport)
|
let transport1: TcpTransport = newTransport(TcpTransport)
|
||||||
await transport1.listen(ma, connHandler)
|
await transport1.listen(ma, connHandler)
|
||||||
|
@ -207,6 +211,7 @@ suite "Mplex":
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
await conn.close()
|
await conn.close()
|
||||||
|
await listenConn.close()
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
@ -218,7 +223,9 @@ suite "Mplex":
|
||||||
|
|
||||||
var count = 1
|
var count = 1
|
||||||
var listenFut: Future[void]
|
var listenFut: Future[void]
|
||||||
|
var listenConn: Connection
|
||||||
proc connHandler(conn: Connection) {.async, gcsafe.} =
|
proc connHandler(conn: Connection) {.async, gcsafe.} =
|
||||||
|
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!"
|
||||||
|
@ -250,6 +257,8 @@ suite "Mplex":
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
await conn.close()
|
await conn.close()
|
||||||
|
await listenConn.close()
|
||||||
|
await allFutures(dialFut, listenFut)
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
|
Loading…
Reference in New Issue