http2: fix test goroutine
This PR fixes the `TestTransportAbortClosesPipes()` test, which was calling `T.Fatal()` from inside a goroutine. `testing.T.Fatal()` is a convenience function that calls `testing.T.Log()` before `testing.T.FailNow()`.
From the godoc for `testing.T.FailNow()`:
> FailNow must be called from the goroutine running the test or benchmark function, not from other goroutines created during the test. Calling FailNow does not stop those other goroutines.
Change-Id: I34d13fc5a14be8b00bee7eae590781bb1ef3ae55
GitHub-Last-Rev: c3929733c5ddbf6cbb41f403aae6ca9a664a48fb
GitHub-Pull-Request: golang/net#56
Reviewed-on: https://go-review.googlesource.com/c/net/+/203479
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/http2/transport_test.go b/http2/transport_test.go
index 922688b..3a3de2e 100644
--- a/http2/transport_test.go
+++ b/http2/transport_test.go
@@ -349,33 +349,35 @@
defer st.Close()
defer close(shutdown) // we must shutdown before st.Close() to avoid hanging
- done := make(chan struct{})
- requestMade := make(chan struct{})
+ errCh := make(chan error)
go func() {
- defer close(done)
+ defer close(errCh)
tr := &Transport{TLSClientConfig: tlsConfigInsecure}
req, err := http.NewRequest("GET", st.ts.URL, nil)
if err != nil {
- t.Fatal(err)
+ errCh <- err
+ return
}
res, err := tr.RoundTrip(req)
if err != nil {
- t.Fatal(err)
+ errCh <- err
+ return
}
defer res.Body.Close()
- close(requestMade)
+ st.closeConn()
_, err = ioutil.ReadAll(res.Body)
if err == nil {
- t.Error("expected error from res.Body.Read")
+ errCh <- errors.New("expected error from res.Body.Read")
+ return
}
}()
- <-requestMade
- // Now force the serve loop to end, via closing the connection.
- st.closeConn()
- // deadlock? that's a bug.
select {
- case <-done:
+ case err := <-errCh:
+ if err != nil {
+ t.Fatal(err)
+ }
+ // deadlock? that's a bug.
case <-time.After(3 * time.Second):
t.Fatal("timeout")
}