This probably fixes the failure mode seen in
https://build.golang.org/log/
e73acfd930cbe82302505cac0041d9883e2360c5.
If not, allowing the test to deadlock and dump goroutines
should produce better debugging information than the existing
"didn't return in an expected time" failure message.
For #58901.
Change-Id: Ie0bb1887a4329d2f6b0e7348a4820af71385494e
Reviewed-on: https://go-review.googlesource.com/c/go/+/548881
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
ln := newLocalListener(t, "tcp")
defer ln.Close()
- max := time.NewTimer(time.Second)
- defer max.Stop()
- ch := make(chan error)
- go func() {
- if err := ln.(*TCPListener).SetDeadline(noDeadline); err != nil {
- t.Error(err)
- }
- if err := ln.(*TCPListener).SetDeadline(time.Now().Add(10 * time.Millisecond)); err != nil {
- t.Error(err)
- }
- c, err := ln.Accept()
- if err == nil {
- c.Close()
- }
- ch <- err
- }()
+ if err := ln.(*TCPListener).SetDeadline(noDeadline); err != nil {
+ t.Error(err)
+ }
+ if err := ln.(*TCPListener).SetDeadline(time.Now().Add(10 * time.Millisecond)); err != nil {
+ t.Error(err)
+ }
+ c, err := ln.Accept()
+ if err == nil {
+ c.Close()
+ }
- select {
- case <-max.C:
- ln.Close()
- <-ch // wait for tester goroutine to stop
- t.Fatal("Accept didn't return in an expected time")
- case err := <-ch:
- if perr := parseAcceptError(err); perr != nil {
- t.Error(perr)
- }
- if !isDeadlineExceeded(err) {
- t.Fatal(err)
- }
+ if perr := parseAcceptError(err); perr != nil {
+ t.Error(perr)
+ }
+ if !isDeadlineExceeded(err) {
+ t.Fatal(err)
}
}