Skip to content

Commit fe62a9e

Browse files
committed
crypto/tls: remove unused variable in benchmark code
This fixes `go test go/types`. https://golang.org/cl/23487/ introduced this code which contains two unused variables (declared and assigned to, but never read). cmd/compile doesn't report the error due open issue golang#8560 (the variables are assigned to in a closure), but go/types does. The build bot only runs go/types tests in -short mode (which doesn't typecheck the std lib), hence this doesn't show up on the dashboard either. We cannot call b.Fatal and friends in the goroutine. Communicating the error to the invoking function requires a channel or a mutex. Unless the channel/sycnhronized variable is tested in each iteration that follows, the iteration blocks if there's a failure. Testing in each iteration may affect benchmark times. One could use a time-out but that time depends on the underlying system. Panicking seems good enough in this unlikely case; better than hanging or affecting benchmark times. Change-Id: Idce1172da8058e580fa3b3e398825b0eb4316325 Reviewed-on: https://go-review.googlesource.com/23528 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e106122 commit fe62a9e

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

src/crypto/tls/tls_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,20 +481,19 @@ func throughput(b *testing.B, totalBytes int64, dynamicRecordSizingDisabled bool
481481

482482
N := b.N
483483

484-
var serr error
485484
go func() {
486485
for i := 0; i < N; i++ {
487486
sconn, err := ln.Accept()
488487
if err != nil {
489-
serr = err
490-
return
488+
// panic rather than synchronize to avoid benchmark overhead
489+
// (cannot call b.Fatal in goroutine)
490+
panic(fmt.Errorf("accept: %v", err))
491491
}
492492
serverConfig := *testConfig
493493
serverConfig.DynamicRecordSizingDisabled = dynamicRecordSizingDisabled
494494
srv := Server(sconn, &serverConfig)
495495
if err := srv.Handshake(); err != nil {
496-
serr = fmt.Errorf("handshake: %v", err)
497-
return
496+
panic(fmt.Errorf("handshake: %v", err))
498497
}
499498
io.Copy(srv, srv)
500499
}
@@ -570,20 +569,19 @@ func latency(b *testing.B, bps int, dynamicRecordSizingDisabled bool) {
570569

571570
N := b.N
572571

573-
var serr error
574572
go func() {
575573
for i := 0; i < N; i++ {
576574
sconn, err := ln.Accept()
577575
if err != nil {
578-
serr = err
579-
return
576+
// panic rather than synchronize to avoid benchmark overhead
577+
// (cannot call b.Fatal in goroutine)
578+
panic(fmt.Errorf("accept: %v", err))
580579
}
581580
serverConfig := *testConfig
582581
serverConfig.DynamicRecordSizingDisabled = dynamicRecordSizingDisabled
583582
srv := Server(&slowConn{sconn, bps}, &serverConfig)
584583
if err := srv.Handshake(); err != nil {
585-
serr = fmt.Errorf("handshake: %v", err)
586-
return
584+
panic(fmt.Errorf("handshake: %v", err))
587585
}
588586
io.Copy(srv, srv)
589587
}

0 commit comments

Comments
 (0)