From cbcba9f9b6779ae2b98a23573ca73fa92b1837d6 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Sat, 28 May 2016 03:20:11 +0900 Subject: [PATCH] crypto/tls: fix race in Benchmark{Throughput,Latency} Fixes #15864. Change-Id: Ic12aa3654bf0b7e4a26df20ea92d07d7efe7339c Reviewed-on: https://go-review.googlesource.com/23504 Reviewed-by: David Chase --- tls_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tls_test.go b/tls_test.go index 4fbe4b2..8dc4533 100644 --- a/tls_test.go +++ b/tls_test.go @@ -479,9 +479,11 @@ func throughput(b *testing.B, totalBytes int64, dynamicRecordSizingDisabled bool ln := newLocalListener(b) defer ln.Close() + N := b.N + var serr error go func() { - for i := 0; i < b.N; i++ { + for i := 0; i < N; i++ { sconn, err := ln.Accept() if err != nil { serr = err @@ -504,7 +506,7 @@ func throughput(b *testing.B, totalBytes int64, dynamicRecordSizingDisabled bool buf := make([]byte, 1<<16) chunks := int(math.Ceil(float64(totalBytes) / float64(len(buf)))) - for i := 0; i < b.N; i++ { + for i := 0; i < N; i++ { conn, err := Dial("tcp", ln.Addr().String(), &clientConfig) if err != nil { b.Fatal(err) @@ -566,9 +568,11 @@ func latency(b *testing.B, bps int, dynamicRecordSizingDisabled bool) { ln := newLocalListener(b) defer ln.Close() + N := b.N + var serr error go func() { - for i := 0; i < b.N; i++ { + for i := 0; i < N; i++ { sconn, err := ln.Accept() if err != nil { serr = err @@ -591,7 +595,7 @@ func latency(b *testing.B, bps int, dynamicRecordSizingDisabled bool) { buf := make([]byte, 16384) peek := make([]byte, 1) - for i := 0; i < b.N; i++ { + for i := 0; i < N; i++ { conn, err := Dial("tcp", ln.Addr().String(), &clientConfig) if err != nil { b.Fatal(err)