migrate integration tests away from Ginkgo (#4736)

* use require in benchmark tests

* translate the QLOGDIR test

* translate handshake tests

* translate the handshake RTT tests

* translate the early data test

* translate the MTU tests

* translate the key update test

* translate the stateless reset tests

* translate the packetization test

* translate the close test

* translate the resumption test

* translate the tracer test

* translate the connection ID length test

* translate the RTT tests

* translate the multiplexing tests

* translate the drop tests

* translate the handshake drop tests

* translate the 0-RTT tests

* translate the hotswap test

* translate the stream test

* translate the unidirectional stream test

* translate the timeout tests

* translate the MITM test

* rewrite the datagram tests

* translate the cancellation tests

* translate the deadline tests

* translate the test helpers
This commit is contained in:
Marten Seemann
2024-12-16 23:43:59 +08:00
committed by GitHub
parent 5e198b0db1
commit 691086db7f
29 changed files with 5775 additions and 6143 deletions

View File

@@ -5,74 +5,80 @@ import (
"fmt"
"net"
"sync/atomic"
"testing"
"time"
"github.com/quic-go/quic-go"
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
)
var _ = Describe("Connection ID lengths tests", func() {
It("retransmits the CONNECTION_CLOSE packet", func() {
server, err := quic.ListenAddr(
"localhost:0",
getTLSConfig(),
getQuicConfig(&quic.Config{
DisablePathMTUDiscovery: true,
}),
)
Expect(err).ToNot(HaveOccurred())
defer server.Close()
func TestConnectionCloseRetransmission(t *testing.T) {
server, err := quic.ListenAddr(
"localhost:0",
getTLSConfig(),
getQuicConfig(&quic.Config{DisablePathMTUDiscovery: true}),
)
require.NoError(t, err)
defer server.Close()
var drop atomic.Bool
dropped := make(chan []byte, 100)
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
RemoteAddr: fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
DelayPacket: func(dir quicproxy.Direction, _ []byte) time.Duration {
return 5 * time.Millisecond // 10ms RTT
},
DropPacket: func(dir quicproxy.Direction, b []byte) bool {
if drop := drop.Load(); drop && dir == quicproxy.DirectionOutgoing {
dropped <- b
return true
}
return false
},
})
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
conn, err := quic.DialAddr(
context.Background(),
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(nil),
)
Expect(err).ToNot(HaveOccurred())
defer conn.CloseWithError(0, "")
sconn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
time.Sleep(100 * time.Millisecond)
drop.Store(true)
sconn.CloseWithError(1337, "closing")
// send 100 packets
for i := 0; i < 100; i++ {
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("foobar"))
Expect(err).ToNot(HaveOccurred())
time.Sleep(time.Millisecond)
}
// Expect retransmissions of the CONNECTION_CLOSE for the
// 1st, 2nd, 4th, 8th, 16th, 32th, 64th packet: 7 in total (+1 for the original packet)
Eventually(dropped).Should(HaveLen(8))
first := <-dropped
for len(dropped) > 0 {
Expect(<-dropped).To(Equal(first)) // these packets are all identical
}
var drop atomic.Bool
dropped := make(chan []byte, 100)
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
RemoteAddr: fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
DelayPacket: func(quicproxy.Direction, []byte) time.Duration {
return 5 * time.Millisecond // 10ms RTT
},
DropPacket: func(dir quicproxy.Direction, b []byte) bool {
if drop := drop.Load(); drop && dir == quicproxy.DirectionOutgoing {
dropped <- b
return true
}
return false
},
})
})
require.NoError(t, err)
defer proxy.Close()
conn, err := quic.DialAddr(
context.Background(),
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(nil),
)
require.NoError(t, err)
defer conn.CloseWithError(0, "")
sconn, err := server.Accept(context.Background())
require.NoError(t, err)
time.Sleep(100 * time.Millisecond)
drop.Store(true)
sconn.CloseWithError(1337, "closing")
// send 100 packets
for i := 0; i < 100; i++ {
str, err := conn.OpenStream()
require.NoError(t, err)
_, err = str.Write([]byte("foobar"))
require.NoError(t, err)
time.Sleep(time.Millisecond)
}
// Expect retransmissions of the CONNECTION_CLOSE for the
// 1st, 2nd, 4th, 8th, 16th, 32th, 64th packet: 7 in total (+1 for the original packet)
var packets [][]byte
for i := 0; i < 8; i++ {
select {
case p := <-dropped:
packets = append(packets, p)
case <-time.After(time.Second):
t.Fatal("timeout waiting for CONNECTION_CLOSE retransmission")
}
}
// verify all retransmitted packets were identical
for i := 1; i < len(packets); i++ {
require.Equal(t, packets[0], packets[i])
}
}