Fix Serve benchmark failures (#734)

* Fix Serve benchmark failures

At present, these benchmarks don't actually work or measure anything.
SetQuestion must have a fully qualified domain name (trailing dot) to
be valid. Because the question wasn't valid, the request never reached
the server and was rejected by the client.

With the error check added, the benchmarks started failing with:
--- FAIL: BenchmarkServe
    server_test.go:346: Exchange failed: dns: domain must be fully qualified

* Enable Serve6 benchmark

Currently this benchmark isn't run as it's not exported.

* Only enable BenchmarkServe6 when IPv6 is supported

The Serve6 benchmark has been disabled since 2014 (in 28d936c032)
because it doesn't play nice with Travis. We can just skip the benchmark
if it fails to bind to an IPv6 address.
This commit is contained in:
Tom Thorogood 2018-09-09 01:40:56 +09:30 committed by Miek Gieben
parent 9a34f54f7a
commit 3ce7efeace
1 changed files with 20 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
"io"
"net"
"runtime"
"strings"
"sync"
"testing"
"time"
@ -337,33 +338,42 @@ func BenchmarkServe(b *testing.B) {
c := new(Client)
m := new(Msg)
m.SetQuestion("miek.nl", TypeSOA)
m.SetQuestion("miek.nl.", TypeSOA)
b.StartTimer()
for i := 0; i < b.N; i++ {
c.Exchange(m, addrstr)
_, _, err := c.Exchange(m, addrstr)
if err != nil {
b.Fatalf("Exchange failed: %v", err)
}
}
runtime.GOMAXPROCS(a)
}
func benchmarkServe6(b *testing.B) {
func BenchmarkServe6(b *testing.B) {
b.StopTimer()
HandleFunc("miek.nl.", HelloServer)
defer HandleRemove("miek.nl.")
a := runtime.GOMAXPROCS(4)
s, addrstr, err := RunLocalUDPServer("[::1]:0")
if err != nil {
if strings.Contains(err.Error(), "bind: cannot assign requested address") {
b.Skip("missing IPv6 support")
}
b.Fatalf("unable to run test server: %v", err)
}
defer s.Shutdown()
c := new(Client)
m := new(Msg)
m.SetQuestion("miek.nl", TypeSOA)
m.SetQuestion("miek.nl.", TypeSOA)
b.StartTimer()
for i := 0; i < b.N; i++ {
c.Exchange(m, addrstr)
_, _, err := c.Exchange(m, addrstr)
if err != nil {
b.Fatalf("Exchange failed: %v", err)
}
}
runtime.GOMAXPROCS(a)
}
@ -390,10 +400,13 @@ func BenchmarkServeCompress(b *testing.B) {
c := new(Client)
m := new(Msg)
m.SetQuestion("miek.nl", TypeSOA)
m.SetQuestion("miek.nl.", TypeSOA)
b.StartTimer()
for i := 0; i < b.N; i++ {
c.Exchange(m, addrstr)
_, _, err := c.Exchange(m, addrstr)
if err != nil {
b.Fatalf("Exchange failed: %v", err)
}
}
runtime.GOMAXPROCS(a)
}