forked from quic-go/quic-go
add a benchmark integration test for performing handshakes
This commit is contained in:
45
integrationtests/self/benchmark_test.go
Normal file
45
integrationtests/self/benchmark_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package self_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
)
|
||||
|
||||
func BenchmarkHandshake(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
ln, err := quic.ListenAddr("localhost:0", tlsConfig, nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
connChan := make(chan quic.Connection, 1)
|
||||
go func() {
|
||||
for {
|
||||
conn, err := ln.Accept(context.Background())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
connChan <- conn
|
||||
}
|
||||
}()
|
||||
|
||||
conn, err := net.ListenUDP("udp", nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c, err := quic.Dial(conn, ln.Addr(), "localhost", tlsClientConfig, nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
<-connChan
|
||||
c.CloseWithError(0, "")
|
||||
}
|
||||
}
|
||||
@@ -106,10 +106,6 @@ var (
|
||||
func init() {
|
||||
flag.StringVar(&logFileName, "logfile", "", "log file")
|
||||
flag.BoolVar(&enableQlog, "qlog", false, "enable qlog")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
mrand.Seed(GinkgoRandomSeed())
|
||||
|
||||
ca, caPrivateKey, err := generateCA()
|
||||
if err != nil {
|
||||
@@ -138,6 +134,10 @@ var _ = BeforeSuite(func() {
|
||||
RootCAs: root,
|
||||
NextProtos: []string{alpn},
|
||||
}
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
mrand.Seed(GinkgoRandomSeed())
|
||||
|
||||
if enableQlog {
|
||||
quicConfigTracer = qlog.NewTracer(func(p logging.Perspective, connectionID []byte) io.WriteCloser {
|
||||
|
||||
Reference in New Issue
Block a user