forked from quic-go/quic-go
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:
@@ -9,6 +9,7 @@ import (
|
||||
mrand "math/rand"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
@@ -17,30 +18,29 @@ import (
|
||||
"github.com/quic-go/quic-go/metrics"
|
||||
"github.com/quic-go/quic-go/qlog"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var _ = Describe("Tracer tests", func() {
|
||||
func TestTracerHandshake(t *testing.T) {
|
||||
addTracers := func(pers protocol.Perspective, conf *quic.Config) *quic.Config {
|
||||
enableQlog := mrand.Int()%2 != 0
|
||||
enableMetrcis := mrand.Int()%2 != 0
|
||||
enableMetrics := mrand.Int()%2 != 0
|
||||
enableCustomTracer := mrand.Int()%2 != 0
|
||||
|
||||
fmt.Fprintf(GinkgoWriter, "%s using qlog: %t, metrics: %t, custom: %t\n", pers, enableQlog, enableMetrcis, enableCustomTracer)
|
||||
t.Logf("%s using qlog: %t, metrics: %t, custom: %t", pers, enableQlog, enableMetrics, enableCustomTracer)
|
||||
|
||||
var tracerConstructors []func(context.Context, logging.Perspective, quic.ConnectionID) *logging.ConnectionTracer
|
||||
if enableQlog {
|
||||
tracerConstructors = append(tracerConstructors, func(_ context.Context, p logging.Perspective, connID quic.ConnectionID) *logging.ConnectionTracer {
|
||||
if mrand.Int()%2 == 0 { // simulate that a qlog collector might only want to log some connections
|
||||
fmt.Fprintf(GinkgoWriter, "%s qlog tracer deciding to not trace connection %s\n", p, connID)
|
||||
t.Logf("%s qlog tracer deciding to not trace connection %s", p, connID)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(GinkgoWriter, "%s qlog tracing connection %s\n", p, connID)
|
||||
t.Logf("%s qlog tracing connection %s", p, connID)
|
||||
return qlog.NewConnectionTracer(utils.NewBufferedWriteCloser(bufio.NewWriter(&bytes.Buffer{}), io.NopCloser(nil)), p, connID)
|
||||
})
|
||||
}
|
||||
if enableMetrcis {
|
||||
if enableMetrics {
|
||||
tracerConstructors = append(tracerConstructors, metrics.DefaultConnectionTracer)
|
||||
}
|
||||
if enableCustomTracer {
|
||||
@@ -62,39 +62,21 @@ var _ = Describe("Tracer tests", func() {
|
||||
}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
It("handshakes with a random combination of tracers", func() {
|
||||
t.Run(fmt.Sprintf("run %d", i+1), func(t *testing.T) {
|
||||
if enableQlog {
|
||||
Skip("This test sets tracers and won't produce any qlogs.")
|
||||
t.Skip("This test sets tracers and won't produce any qlogs.")
|
||||
}
|
||||
|
||||
quicClientConf := addTracers(protocol.PerspectiveClient, getQuicConfig(nil))
|
||||
quicServerConf := addTracers(protocol.PerspectiveServer, getQuicConfig(nil))
|
||||
|
||||
serverChan := make(chan *quic.Listener)
|
||||
serverDone := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
defer close(serverDone)
|
||||
ln, err := quic.ListenAddr("localhost:0", getTLSConfig(), quicServerConf)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
serverChan <- ln
|
||||
for {
|
||||
conn, err := ln.Accept(context.Background())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
str, err := conn.OpenUniStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = str.Write(PRData)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str.Close()).To(Succeed())
|
||||
}
|
||||
}()
|
||||
|
||||
ln := <-serverChan
|
||||
ln, err := quic.ListenAddr("localhost:0", getTLSConfig(), quicServerConf)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { require.NoError(t, ln.Close()) })
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(3)
|
||||
for i := 0; i < 3; i++ {
|
||||
for j := 0; j < 3; j++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
conn, err := quic.DialAddr(
|
||||
@@ -103,18 +85,27 @@ var _ = Describe("Tracer tests", func() {
|
||||
getTLSClientConfig(),
|
||||
quicClientConf,
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
defer conn.CloseWithError(0, "")
|
||||
|
||||
sconn, err := ln.Accept(context.Background())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sstr, err := sconn.OpenUniStream()
|
||||
require.NoError(t, err)
|
||||
_, err = sstr.Write(PRData)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, sstr.Close())
|
||||
|
||||
str, err := conn.AcceptUniStream(context.Background())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
data, err := io.ReadAll(str)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(data).To(Equal(PRData))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, PRData, data)
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
ln.Close()
|
||||
Eventually(serverDone).Should(BeClosed())
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user