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,
|
import testvarint,
|
||||||
|
testconnection,
|
||||||
testminprotobuf,
|
testminprotobuf,
|
||||||
teststreamseq,
|
teststreamseq,
|
||||||
testsemaphore
|
testsemaphore
|
||||||
|
@ -26,4 +27,6 @@ import testtcptransport,
|
||||||
testswitch,
|
testswitch,
|
||||||
testnoise,
|
testnoise,
|
||||||
testpeerinfo,
|
testpeerinfo,
|
||||||
|
testpeerstore,
|
||||||
|
testping,
|
||||||
testmplex
|
testmplex
|
||||||
|
|
|
@ -17,10 +17,6 @@ import ./helpers
|
||||||
when defined(nimHasUsed): {.used.}
|
when defined(nimHasUsed): {.used.}
|
||||||
|
|
||||||
suite "Ping":
|
suite "Ping":
|
||||||
teardown:
|
|
||||||
checkTrackers()
|
|
||||||
|
|
||||||
suite "handle ping message":
|
|
||||||
var
|
var
|
||||||
ma {.threadvar.}: MultiAddress
|
ma {.threadvar.}: MultiAddress
|
||||||
serverFut {.threadvar.}: Future[void]
|
serverFut {.threadvar.}: Future[void]
|
||||||
|
@ -56,6 +52,7 @@ suite "Ping":
|
||||||
await transport1.stop()
|
await transport1.stop()
|
||||||
await serverFut
|
await serverFut
|
||||||
await transport2.stop()
|
await transport2.stop()
|
||||||
|
checkTrackers()
|
||||||
|
|
||||||
asyncTest "simple ping":
|
asyncTest "simple ping":
|
||||||
msListen.addHandler(PingCodec, pingProto1)
|
msListen.addHandler(PingCodec, pingProto1)
|
||||||
|
@ -72,35 +69,6 @@ suite "Ping":
|
||||||
|
|
||||||
check not time.isZero()
|
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":
|
asyncTest "ping callback":
|
||||||
msDial.addHandler(PingCodec, pingProto2)
|
msDial.addHandler(PingCodec, pingProto2)
|
||||||
serverFut = transport1.start(ma)
|
serverFut = transport1.start(ma)
|
||||||
|
|
Loading…
Reference in New Issue