Remove asynctest (#36)

This commit is contained in:
Tanguy 2022-08-25 14:37:35 +02:00 committed by GitHub
parent 7e432aeb5c
commit 084413c986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 65 deletions

View File

@ -10,5 +10,4 @@ requires "chronos >= 3.0.0 & < 4.0.0"
requires "nimcrypto >= 0.5.4 & < 0.6.0"
requires "ngtcp2 >= 0.32.0 & < 0.33.0"
requires "upraises >= 0.1.0 & < 0.2.0"
requires "asynctest >= 0.3.0 & < 0.4.0"
requires "unittest2 >= 0.0.4 & < 0.1.0"

View File

@ -1,19 +1,16 @@
import pkg/asynctest/unittest2
import pkg/chronos
import pkg/chronos/unittest2/asynctests
import pkg/quic
suite "api":
let address = initTAddress("127.0.0.1:48579")
var listener: Listener
setup:
listener = listen(address)
let address = initTAddress("127.0.0.1:48579")
var listener = listen(address)
teardown:
await listener.stop()
waitFor listener.stop()
test "opens and drops connections":
asyncTest "opens and drops connections":
let dialing = dial(address)
let accepting = listener.accept()
@ -23,7 +20,7 @@ suite "api":
await outgoing.drop()
await incoming.drop()
test "opens and closes streams":
asyncTest "opens and closes streams":
let dialing = dial(address)
let accepting = listener.accept()
@ -39,7 +36,7 @@ suite "api":
await outgoing.drop()
await incoming.drop()
test "waits until peer closes connection":
asyncTest "waits until peer closes connection":
let dialing = dial(address)
let accepting = listener.accept()
@ -49,7 +46,7 @@ suite "api":
await incoming.close()
await outgoing.waitClosed()
test "accepts multiple incoming connections":
asyncTest "accepts multiple incoming connections":
let accepting1 = listener.accept()
let outgoing1 = await dial(address)
let incoming1 = await accepting1
@ -65,7 +62,7 @@ suite "api":
await incoming1.drop()
await incoming2.drop()
test "writes to and reads from streams":
asyncTest "writes to and reads from streams":
let message = @[1'u8, 2'u8, 3'u8]
let outgoing = await dial(address)

View File

@ -1,13 +1,14 @@
import pkg/asynctest/unittest2
import pkg/chronos
import pkg/chronos/unittest2/asynctests
import pkg/quic/connection
import ../helpers/udp
suite "connections":
let address = initTAddress("127.0.0.1:45346")
setup:
let address = initTAddress("127.0.0.1:45346")
test "handles error when writing to udp transport by closing connection":
asyncTest "handles error when writing to udp transport by closing connection":
let udp = newDatagramTransport()
let connection = newOutgoingConnection(udp, address)

View File

@ -1,21 +1,19 @@
import pkg/asynctest/unittest2
import pkg/chronos
import pkg/chronos/unittest2/asynctests
import pkg/quic
import pkg/quic/listener
import ../helpers/udp
suite "listener":
let address = initTAddress("127.0.0.1:45346")
var listener: Listener
setup:
listener = newListener(address)
let address = initTAddress("127.0.0.1:45346")
var listener = newListener(address)
teardown:
await listener.stop()
waitFor listener.stop()
test "creates connections":
asyncTest "creates connections":
await exampleQuicDatagram().sendTo(address)
let connection = await listener.waitForIncoming()
@ -23,7 +21,7 @@ suite "listener":
await connection.drop()
test "re-uses connection for known connection id":
asyncTest "re-uses connection for known connection id":
let datagram = exampleQuicDatagram()
await datagram.sendTo(address)
await datagram.sendTo(address)
@ -33,7 +31,7 @@ suite "listener":
discard await listener.waitForIncoming.wait(100.milliseconds)
await first.drop()
test "creates new connection for unknown connection id":
asyncTest "creates new connection for unknown connection id":
await exampleQuicDatagram().sendTo(address)
await exampleQuicDatagram().sendTo(address)
@ -43,7 +41,7 @@ suite "listener":
await first.drop()
await second.drop()
test "forgets connection ids when connection closes":
asyncTest "forgets connection ids when connection closes":
let datagram = exampleQuicDatagram()
await datagram.sendTo(address)

View File

@ -1,5 +1,5 @@
import pkg/asynctest/unittest2
import pkg/chronos
import pkg/chronos/unittest2/asynctests
import pkg/quic/errors
import pkg/quic/transport/quicconnection
import pkg/quic/transport/quicclientserver
@ -10,14 +10,14 @@ import ../helpers/addresses
suite "quic connection":
test "sends outgoing datagrams":
asyncTest "sends outgoing datagrams":
let client = newQuicClientConnection(zeroAddress, zeroAddress)
defer: await client.drop()
client.send()
let datagram = await client.outgoing.get()
check datagram.len > 0
test "processes received datagrams":
asyncTest "processes received datagrams":
let client = newQuicClientConnection(zeroAddress, zeroAddress)
defer: await client.drop()
@ -29,13 +29,13 @@ suite "quic connection":
server.receive(datagram)
test "raises error when datagram that starts server connection is invalid":
asyncTest "raises error when datagram that starts server connection is invalid":
let invalid = Datagram(data: @[0'u8])
expect QuicError:
discard newQuicServerConnection(zeroAddress, zeroAddress, invalid)
test "performs handshake":
asyncTest "performs handshake":
let (client, server) = await performHandshake()
defer: await client.drop()
defer: await server.drop()
@ -43,19 +43,19 @@ suite "quic connection":
check client.handshake.isSet()
check server.handshake.isSet()
test "performs handshake multiple times":
asyncTest "performs handshake multiple times":
for i in 1..100:
let (client, server) = await performHandshake()
await client.drop()
await server.drop()
test "returns the current connection ids":
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
test "notifies about id changes":
asyncTest "notifies about id changes":
let (client, server) = await setupConnection()
defer: await client.drop
defer: await server.drop
@ -70,7 +70,7 @@ suite "quic connection":
await server.handshake.wait()
check newId != ConnectionId.default
test "raises ConnectionError when closed":
asyncTest "raises ConnectionError when closed":
let connection = newQuicClientConnection(zeroAddress, zeroAddress)
await connection.drop()
@ -83,7 +83,7 @@ suite "quic connection":
expect ConnectionError:
discard await connection.openStream()
test "has empty list of ids when closed":
asyncTest "has empty list of ids when closed":
let connection = newQuicClientConnection(zeroAddress, zeroAddress)
await connection.drop()

View File

@ -1,6 +1,6 @@
import std/sequtils
import pkg/asynctest/unittest2
import pkg/chronos
import pkg/chronos/unittest2/asynctests
import pkg/quic/errors
import pkg/quic/transport/stream
import pkg/quic/transport/quicconnection
@ -10,47 +10,44 @@ import ../helpers/simulation
import ../helpers/contains
suite "streams":
var client, server: QuicConnection
setup:
(client, server) = await performHandshake()
var (client, server) = waitFor performHandshake()
teardown:
await client.drop()
await server.drop()
waitFor client.drop()
waitFor server.drop()
test "opens uni-directional streams":
asyncTest "opens uni-directional streams":
let stream1, stream2 = await client.openStream(unidirectional = true)
check stream1 != stream2
check stream1.isUnidirectional
check stream2.isUnidirectional
test "opens bi-directional streams":
asyncTest "opens bi-directional streams":
let stream1, stream2 = await client.openStream()
check stream1 != stream2
check not stream1.isUnidirectional
check not stream2.isUnidirectional
test "closes stream":
asyncTest "closes stream":
let stream = await client.openStream()
await stream.close()
test "writes to stream":
asyncTest "writes to stream":
let stream = await client.openStream()
let message = @[1'u8, 2'u8, 3'u8]
await stream.write(message)
check client.outgoing.anyIt(it.data.contains(message))
test "writes zero-length message":
asyncTest "writes zero-length message":
let stream = await client.openStream()
await stream.write(@[])
let datagram = await client.outgoing.get()
check datagram.len > 0
test "raises when reading from or writing to closed stream":
asyncTest "raises when reading from or writing to closed stream":
let stream = await client.openStream()
await stream.close()
@ -60,7 +57,7 @@ suite "streams":
expect QuicError:
await stream.write(@[1'u8, 2'u8, 3'u8])
test "accepts incoming streams":
asyncTest "accepts incoming streams":
let simulation = simulateNetwork(client, server)
let clientStream = await client.openStream()
@ -71,7 +68,7 @@ suite "streams":
await simulation.cancelAndWait()
test "reads from stream":
asyncTest "reads from stream":
let simulation = simulateNetwork(client, server)
let message = @[1'u8, 2'u8, 3'u8]
@ -86,7 +83,7 @@ suite "streams":
await simulation.cancelAndWait()
test "writes long messages to stream":
asyncTest "writes long messages to stream":
let simulation = simulateNetwork(client, server)
let stream = await client.openStream()
@ -99,7 +96,7 @@ suite "streams":
await simulation.cancelAndWait()
test "halts sender until receiver has caught up":
asyncTest "halts sender until receiver has caught up":
let simulation = simulateNetwork(client, server)
let message = repeat(42'u8, sizeof(Ngtcp2Connection.buffer))
@ -120,7 +117,7 @@ suite "streams":
await simulation.cancelAndWait()
test "handles packet loss":
asyncTest "handles packet loss":
let simulation = simulateLossyNetwork(client, server)
let message = @[1'u8, 2'u8, 3'u8]
@ -134,7 +131,7 @@ suite "streams":
await simulation.cancelAndWait()
test "raises when stream is closed by peer":
asyncTest "raises when stream is closed by peer":
let simulation = simulateNetwork(client, server)
let clientStream = await client.openStream()
@ -154,7 +151,7 @@ suite "streams":
await simulation.cancelAndWait()
test "closes stream when underlying connection is closed by peer":
asyncTest "closes stream when underlying connection is closed by peer":
let simulation = simulateNetwork(client, server)
let clientStream = await client.openStream()
@ -170,7 +167,7 @@ suite "streams":
await simulation.cancelAndWait()
test "reads last bytes from stream that is closed by peer":
asyncTest "reads last bytes from stream that is closed by peer":
let simulation = simulateNetwork(client, server)
let message = @[1'u8, 2'u8, 3'u8]

View File

@ -1,5 +1,5 @@
import pkg/asynctest/unittest2
import pkg/chronos
import pkg/chronos/unittest2/asynctests
import pkg/quic/transport/timeout
suite "timeout":
@ -9,14 +9,14 @@ suite "timeout":
body
Moment.now() - start
test "can expire":
asyncTest "can expire":
let duration = measure:
let timeout = newTimeout()
timeout.set(10.milliseconds)
await timeout.expired()
check duration > 10.milliseconds
test "can be reset before expiry":
asyncTest "can be reset before expiry":
let timeout = newTimeout()
timeout.set(10.milliseconds)
let duration = measure:
@ -24,7 +24,7 @@ suite "timeout":
await timeout.expired()
check duration > 20.milliseconds
test "can be reset after expiry":
asyncTest "can be reset after expiry":
let timeout = newTimeout()
timeout.set(10.milliseconds)
await timeout.expired()
@ -33,7 +33,7 @@ suite "timeout":
await timeout.expired()
check duration > 10.milliseconds
test "can be stopped":
asyncTest "can be stopped":
let timeout = newTimeout()
timeout.set(10.milliseconds)
let expiry = timeout.expired()
@ -42,7 +42,7 @@ suite "timeout":
check not expiry.finished()
expiry.cancel()
test "calls callback after expiry":
asyncTest "calls callback after expiry":
var called = false
proc callback = called = true
let timeout = newTimeout(callback)
@ -52,7 +52,7 @@ suite "timeout":
check called
timeout.stop()
test "calls callback multiple times":
asyncTest "calls callback multiple times":
var count = 0
proc callback = inc count
let timeout = newTimeout(callback)
@ -62,7 +62,7 @@ suite "timeout":
await timeout.expired()
check count == 2
test "timeout can be set to a moment in time":
asyncTest "timeout can be set to a moment in time":
let duration = measure:
let timeout = newTimeout()
timeout.set(Moment.fromNow(10.milliseconds))