add a benchmark integration test for performing handshakes

This commit is contained in:
Marten Seemann
2023-01-03 17:17:06 +13:00
parent 5b72f4c900
commit b791bb6cdf
2 changed files with 49 additions and 4 deletions

View 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, "")
}
}