make the benchmark suite compatible with Go 1.13

Unfortunately, there doesn't seem to be a way to keep the samples flag.
This commit is contained in:
Marten Seemann
2019-09-05 10:01:15 +07:00
parent d1489e5045
commit 305d6e0fbe
5 changed files with 77 additions and 70 deletions

View File

@@ -25,10 +25,10 @@ jobs:
command: go version
- run:
name: "Run benchmark tests"
command: ginkgo -randomizeAllSpecs -trace benchmark -- -samples=1
command: ginkgo -randomizeAllSpecs -trace benchmark -- -size=10
- run:
name: "Run benchmark tests with race detector"
command: ginkgo -race -randomizeAllSpecs -trace benchmark -- -samples=1 -size=10
command: ginkgo -race -randomizeAllSpecs -trace benchmark -- -size=5
- run:
name: "Run tools tests"
command: ginkgo -race -r -v -randomizeAllSpecs -trace integrationtests/tools

View File

@@ -16,11 +16,11 @@ fi
if [ ${TESTMODE} == "integration" ]; then
# run benchmark tests
ginkgo -randomizeAllSpecs -randomizeSuites -trace benchmark -- -samples=1
ginkgo -randomizeAllSpecs -randomizeSuites -trace benchmark -- -size=10
# run benchmark tests with the Go race detector
# The Go race detector only works on amd64.
if [ ${TRAVIS_GOARCH} == 'amd64' ]; then
ginkgo -race -randomizeAllSpecs -randomizeSuites -trace benchmark -- -samples=1 -size=10
ginkgo -race -randomizeAllSpecs -randomizeSuites -trace benchmark -- -size=5
fi
# run integration tests
ginkgo -r -v -randomizeAllSpecs -randomizeSuites -trace integrationtests

View File

@@ -27,7 +27,7 @@ install:
build_script:
- ginkgo -r -v -randomizeAllSpecs -randomizeSuites -trace -skipPackage benchmark,integrationtests
- ginkgo -randomizeAllSpecs -randomizeSuites -trace benchmark -- -samples=1
- ginkgo -randomizeAllSpecs -randomizeSuites -trace benchmark -- -size=10
test: off

View File

@@ -2,6 +2,7 @@ package benchmark
import (
"flag"
"math/rand"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -15,12 +16,15 @@ func TestBenchmark(t *testing.T) {
}
var (
size int // file size in MB, will be read from flags
samples int // number of samples for Measure, will be read from flags
size int // file size in MB, will be read from flags
)
func init() {
flag.IntVar(&size, "size", 50, "data length (in MB)")
flag.IntVar(&samples, "samples", 6, "number of samples")
flag.Parse()
}
var _ = BeforeSuite(func() {
rand.Seed(GinkgoRandomSeed())
flag.Parse()
})

View File

@@ -13,78 +13,81 @@ import (
_ "github.com/lucas-clemente/quic-go/integrationtests/tools/testlog"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/testdata"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func init() {
var _ = Describe("Benchmarks", func() {
dataLen := size * /* MB */ 1e6
data := make([]byte, dataLen)
rand.Seed(GinkgoRandomSeed())
rand.Read(data) // no need to check for an error. math.Rand.Read never errors
var _ = Describe("Benchmarks", func() {
for i := range protocol.SupportedVersions {
version := protocol.SupportedVersions[i]
for i := range protocol.SupportedVersions {
version := protocol.SupportedVersions[i]
Context(fmt.Sprintf("with version %s", version), func() {
var data []byte
var dataLen int
Context(fmt.Sprintf("with version %s", version), func() {
Measure(fmt.Sprintf("transferring a %d MB file", size), func(b Benchmarker) {
var ln quic.Listener
serverAddr := make(chan net.Addr)
handshakeChan := make(chan struct{})
// start the server
go func() {
defer GinkgoRecover()
var err error
tlsConf := testdata.GetTLSConfig()
tlsConf.NextProtos = []string{"benchmark"}
ln, err = quic.ListenAddr(
"localhost:0",
tlsConf,
&quic.Config{Versions: []protocol.VersionNumber{version}},
)
Expect(err).ToNot(HaveOccurred())
serverAddr <- ln.Addr()
sess, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
// wait for the client to complete the handshake before sending the data
// this should not be necessary, but due to timing issues on the CIs, this is necessary to avoid sending too many undecryptable packets
<-handshakeChan
str, err := sess.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(data)
Expect(err).ToNot(HaveOccurred())
err = str.Close()
Expect(err).ToNot(HaveOccurred())
}()
BeforeEach(func() {
dataLen = size * /* MB */ 1e6
data = make([]byte, dataLen)
rand.Read(data) // no need to check for an error. math.Rand.Read never errors
})
// start the client
addr := <-serverAddr
sess, err := quic.DialAddr(
addr.String(),
&tls.Config{InsecureSkipVerify: true, NextProtos: []string{"benchmark"}},
Measure("transferring a file", func(b Benchmarker) {
var ln quic.Listener
serverAddr := make(chan net.Addr)
handshakeChan := make(chan struct{})
// start the server
go func() {
defer GinkgoRecover()
var err error
tlsConf := testdata.GetTLSConfig()
tlsConf.NextProtos = []string{"benchmark"}
ln, err = quic.ListenAddr(
"localhost:0",
tlsConf,
&quic.Config{Versions: []protocol.VersionNumber{version}},
)
Expect(err).ToNot(HaveOccurred())
close(handshakeChan)
str, err := sess.AcceptStream(context.Background())
serverAddr <- ln.Addr()
sess, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
// wait for the client to complete the handshake before sending the data
// this should not be necessary, but due to timing issues on the CIs, this is necessary to avoid sending too many undecryptable packets
<-handshakeChan
str, err := sess.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(data)
Expect(err).ToNot(HaveOccurred())
err = str.Close()
Expect(err).ToNot(HaveOccurred())
}()
buf := &bytes.Buffer{}
// measure the time it takes to download the dataLen bytes
// note we're measuring the time for the transfer, i.e. excluding the handshake
runtime := b.Time("transfer time", func() {
_, err := io.Copy(buf, str)
Expect(err).NotTo(HaveOccurred())
})
Expect(buf.Bytes()).To(Equal(data))
// start the client
addr := <-serverAddr
sess, err := quic.DialAddr(
addr.String(),
&tls.Config{InsecureSkipVerify: true, NextProtos: []string{"benchmark"}},
&quic.Config{Versions: []protocol.VersionNumber{version}},
)
Expect(err).ToNot(HaveOccurred())
close(handshakeChan)
str, err := sess.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
b.RecordValue("transfer rate [MB/s]", float64(dataLen)/1e6/runtime.Seconds())
buf := &bytes.Buffer{}
// measure the time it takes to download the dataLen bytes
// note we're measuring the time for the transfer, i.e. excluding the handshake
runtime := b.Time("transfer time", func() {
_, err := io.Copy(buf, str)
Expect(err).NotTo(HaveOccurred())
})
Expect(buf.Bytes()).To(Equal(data))
ln.Close()
sess.Close()
}, samples)
})
}
})
}
b.RecordValue("transfer rate [MB/s]", float64(dataLen)/1e6/runtime.Seconds())
ln.Close()
sess.Close()
}, 3)
})
}
})