mirror of https://github.com/vacp2p/nim-quic.git
tests
This commit is contained in:
parent
a4e7cdbfc9
commit
1909a7d80b
|
@ -10,6 +10,7 @@ export Stream, close, read, write
|
|||
type
|
||||
Connection* = ref object of RootObj
|
||||
udp: DatagramTransport
|
||||
remote: TransportAddress
|
||||
quic: QuicConnection
|
||||
loop: Future[void]
|
||||
onClose: Opt[proc() {.gcsafe, upraises: [].}]
|
||||
|
@ -71,6 +72,7 @@ proc newIncomingConnection*(udp: DatagramTransport,
|
|||
let connection = IncomingConnection(udp: udp, quic: quic, closed: closed)
|
||||
proc onDisconnect {.async.} =
|
||||
await connection.disconnect()
|
||||
connection.remote = remote
|
||||
quic.disconnect = Opt.some(onDisconnect)
|
||||
connection.startSending(remote)
|
||||
connection
|
||||
|
@ -82,6 +84,7 @@ proc newOutgoingConnection*(udp: DatagramTransport,
|
|||
let connection = OutgoingConnection(udp: udp, quic: quic, closed: closed)
|
||||
proc onDisconnect {.async.} =
|
||||
await connection.disconnect()
|
||||
connection.remote = remote
|
||||
quic.disconnect = Opt.some(onDisconnect)
|
||||
connection.startSending(remote)
|
||||
connection
|
||||
|
@ -94,7 +97,7 @@ proc receive*(connection: Connection, datagram: Datagram) =
|
|||
|
||||
proc remoteAddress*(connection: Connection): TransportAddress {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
connection.udp.remoteAddress()
|
||||
connection.remote
|
||||
|
||||
proc localAddress*(connection: Connection): TransportAddress {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
|
|
|
@ -4,8 +4,8 @@ import pkg/quic
|
|||
|
||||
suite "api":
|
||||
setup:
|
||||
let address = initTAddress("127.0.0.1:48579")
|
||||
var listener = listen(address)
|
||||
var listener = listen(initTAddress("127.0.0.1:0"))
|
||||
let address = listener.localAddress
|
||||
|
||||
teardown:
|
||||
waitFor listener.stop()
|
||||
|
@ -17,6 +17,11 @@ suite "api":
|
|||
let outgoing = await dialing
|
||||
let incoming = await accepting
|
||||
|
||||
check:
|
||||
outgoing.remoteAddress.port == address.port
|
||||
outgoing.localAddress.port == incoming.remoteAddress.port
|
||||
incoming.localAddress.port == address.port
|
||||
|
||||
await outgoing.drop()
|
||||
await incoming.drop()
|
||||
|
||||
|
|
|
@ -7,8 +7,10 @@ import ../helpers/udp
|
|||
suite "listener":
|
||||
|
||||
setup:
|
||||
let address = initTAddress("127.0.0.1:45346")
|
||||
var listener = newListener(address)
|
||||
var listener = newListener(initTAddress("127.0.0.1:0"))
|
||||
let address = listener.localAddress
|
||||
|
||||
check address.port != Port(0)
|
||||
|
||||
teardown:
|
||||
waitFor listener.stop()
|
||||
|
|
Loading…
Reference in New Issue