mirror of https://github.com/vacp2p/nim-libp2p.git
Add missing test to testnative (#618)
* add missing tests * fix testping
This commit is contained in:
parent
f274bfe19d
commit
62ca6dd9a0
|
@ -1,4 +1,5 @@
|
|||
import testvarint,
|
||||
testconnection,
|
||||
testminprotobuf,
|
||||
teststreamseq,
|
||||
testsemaphore
|
||||
|
@ -26,4 +27,6 @@ import testtcptransport,
|
|||
testswitch,
|
||||
testnoise,
|
||||
testpeerinfo,
|
||||
testpeerstore,
|
||||
testping,
|
||||
testmplex
|
||||
|
|
|
@ -17,10 +17,6 @@ import ./helpers
|
|||
when defined(nimHasUsed): {.used.}
|
||||
|
||||
suite "Ping":
|
||||
teardown:
|
||||
checkTrackers()
|
||||
|
||||
suite "handle ping message":
|
||||
var
|
||||
ma {.threadvar.}: MultiAddress
|
||||
serverFut {.threadvar.}: Future[void]
|
||||
|
@ -56,6 +52,7 @@ suite "Ping":
|
|||
await transport1.stop()
|
||||
await serverFut
|
||||
await transport2.stop()
|
||||
checkTrackers()
|
||||
|
||||
asyncTest "simple ping":
|
||||
msListen.addHandler(PingCodec, pingProto1)
|
||||
|
@ -72,35 +69,6 @@ suite "Ping":
|
|||
|
||||
check not time.isZero()
|
||||
|
||||
asyncTest "networked cancel ping":
|
||||
proc testPing(): Future[void] {.async.} =
|
||||
let baseMa = Multiaddress.init("/ip4/127.0.0.1/tcp/0").tryGet()
|
||||
|
||||
let transport: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
||||
let transportdialer: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
||||
asyncSpawn transport.start(baseMa)
|
||||
|
||||
proc acceptHandler() {.async, gcsafe.} =
|
||||
let handler = Ping.new().handler
|
||||
let conn = await transport.accept()
|
||||
await handler(conn, "na")
|
||||
|
||||
let handlerWait = acceptHandler()
|
||||
|
||||
let streamTransport = await transportdialer.dial(transport.ma)
|
||||
|
||||
discard await pingProto2.ping(streamTransport)
|
||||
|
||||
for pollCount in 0..20:
|
||||
#echo "Polling ", pollCount, " times"
|
||||
let p = testPing()
|
||||
for _ in 0..<pollCount:
|
||||
if p.finished: break
|
||||
poll()
|
||||
if p.finished: break #We actually finished the sequence
|
||||
await p.cancelAndWait()
|
||||
check p.cancelled
|
||||
|
||||
asyncTest "ping callback":
|
||||
msDial.addHandler(PingCodec, pingProto2)
|
||||
serverFut = transport1.start(ma)
|
||||
|
|
Loading…
Reference in New Issue