From 1909a7d80b2785455e0176a379e4a2e7f691c37d Mon Sep 17 00:00:00 2001 From: Tanguy Date: Tue, 17 Jan 2023 17:26:44 +0100 Subject: [PATCH] tests --- quic/connection.nim | 5 ++++- tests/quic/testApi.nim | 9 +++++++-- tests/quic/testListener.nim | 6 ++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/quic/connection.nim b/quic/connection.nim index b2447f6..e0e6798 100644 --- a/quic/connection.nim +++ b/quic/connection.nim @@ -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].} = diff --git a/tests/quic/testApi.nim b/tests/quic/testApi.nim index fb0675a..189d362 100644 --- a/tests/quic/testApi.nim +++ b/tests/quic/testApi.nim @@ -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() diff --git a/tests/quic/testListener.nim b/tests/quic/testListener.nim index bf8bce6..45c1161 100644 --- a/tests/quic/testListener.nim +++ b/tests/quic/testListener.nim @@ -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()