From 2161c3b769afd15dff8a32e92bcedeb405e0542d Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 16 Dec 2020 17:38:12 +0100 Subject: [PATCH] Combine testNgtcp2Connection & testQuicConnection --- tests/quic/testNgtcp2Connection.nim | 72 ----------------------------- tests/quic/testQuicConnection.nim | 63 +++++++++++++++++++++++++ tests/testAll.nim | 1 - 3 files changed, 63 insertions(+), 73 deletions(-) delete mode 100644 tests/quic/testNgtcp2Connection.nim diff --git a/tests/quic/testNgtcp2Connection.nim b/tests/quic/testNgtcp2Connection.nim deleted file mode 100644 index 671e832..0000000 --- a/tests/quic/testNgtcp2Connection.nim +++ /dev/null @@ -1,72 +0,0 @@ -import std/unittest -import pkg/chronos -import pkg/quic/transport/quicconnection -import pkg/quic/transport/quicclient -import pkg/quic/transport/quicserver -import pkg/quic/udp/datagram -import pkg/quic/transport/connectionid -import ../helpers/asynctest -import ../helpers/simulation -import ../helpers/addresses - -suite "quic connection": - - asynctest "sends outgoing datagrams": - let client = newQuicClientConnection(zeroAddress, zeroAddress) - defer: client.drop() - client.send() - let datagram = await client.outgoing.get() - check datagram.len > 0 - - asynctest "processes received datagrams": - let client = newQuicClientConnection(zeroAddress, zeroAddress) - defer: client.drop() - - client.send() - let datagram = await client.outgoing.get() - - let server = newQuicServerConnection(zeroAddress, zeroAddress, datagram) - defer: server.drop() - - server.receive(datagram) - - test "raises error when datagram that starts server connection is invalid": - let invalid = Datagram(data: @[0'u8]) - - expect IOError: - discard newQuicServerConnection(zeroAddress, zeroAddress, invalid) - - asynctest "performs handshake": - let (client, server) = await performHandshake() - defer: client.drop() - defer: server.drop() - - check client.handshake.isSet() - check server.handshake.isSet() - - asynctest "performs handshake multiple times": - for i in 1..100: - let (client, server) = await performHandshake() - client.drop() - server.drop() - - asynctest "returns the current connection ids": - let (client, server) = await setupConnection() - check server.ids.len > 0 - check client.ids.len > 0 - check server.ids != client.ids - - asynctest "notifies about id changes": - let (client, server) = await setupConnection() - defer: client.drop - defer: server.drop - - var newId: ConnectionId - server.onNewId = proc (id: ConnectionId) = - newId = id - - let simulation = simulateNetwork(client, server) - defer: await simulation.cancelAndWait() - - await server.handshake.wait() - check newId != ConnectionId.default diff --git a/tests/quic/testQuicConnection.nim b/tests/quic/testQuicConnection.nim index da3cbc9..c20149c 100644 --- a/tests/quic/testQuicConnection.nim +++ b/tests/quic/testQuicConnection.nim @@ -2,12 +2,75 @@ import std/unittest import pkg/chronos import pkg/quic/transport/quicconnection import pkg/quic/transport/quicclient +import pkg/quic/transport/quicserver import pkg/quic/udp/datagram +import pkg/quic/transport/connectionid import ../helpers/asynctest +import ../helpers/simulation import ../helpers/addresses suite "quic connection": + asynctest "sends outgoing datagrams": + let client = newQuicClientConnection(zeroAddress, zeroAddress) + defer: client.drop() + client.send() + let datagram = await client.outgoing.get() + check datagram.len > 0 + + asynctest "processes received datagrams": + let client = newQuicClientConnection(zeroAddress, zeroAddress) + defer: client.drop() + + client.send() + let datagram = await client.outgoing.get() + + let server = newQuicServerConnection(zeroAddress, zeroAddress, datagram) + defer: server.drop() + + server.receive(datagram) + + test "raises error when datagram that starts server connection is invalid": + let invalid = Datagram(data: @[0'u8]) + + expect IOError: + discard newQuicServerConnection(zeroAddress, zeroAddress, invalid) + + asynctest "performs handshake": + let (client, server) = await performHandshake() + defer: client.drop() + defer: server.drop() + + check client.handshake.isSet() + check server.handshake.isSet() + + asynctest "performs handshake multiple times": + for i in 1..100: + let (client, server) = await performHandshake() + client.drop() + server.drop() + + asynctest "returns the current connection ids": + let (client, server) = await setupConnection() + check server.ids.len > 0 + check client.ids.len > 0 + check server.ids != client.ids + + asynctest "notifies about id changes": + let (client, server) = await setupConnection() + defer: client.drop + defer: server.drop + + var newId: ConnectionId + server.onNewId = proc (id: ConnectionId) = + newId = id + + let simulation = simulateNetwork(client, server) + defer: await simulation.cancelAndWait() + + await server.handshake.wait() + check newId != ConnectionId.default + asynctest "raises ConnectionError when closed": let connection = newQuicClientConnection(zeroAddress, zeroAddress) connection.drop() diff --git a/tests/testAll.nim b/tests/testAll.nim index 0ef1787..30e6e80 100644 --- a/tests/testAll.nim +++ b/tests/testAll.nim @@ -6,7 +6,6 @@ import ./quic/testPackets import ./quic/testVarInts import ./quic/testPacketNumber import ./quic/testConnectionId -import ./quic/testNgtcp2Connection import ./quic/testNgtcp2TransportParameters import ./quic/testNgtcp2PacketInfo import ./quic/testStreams