mirror of https://github.com/golang/go.git
net/http: deflake tests in full mode after t.Parallel additions
https://golang.org/cl/18087 added a bunch of t.Parallel calls, which aren't compatible with the afterTest func. But in short mode, afterTest is a no-op. To keep all.bash (short mode) fast, conditionally set t.Parallel when in short mode, but keep it unset for compatibility with afterFunc otherwise. Fixes #13804 Change-Id: Ie841fbc2544e1ffbee43ba1afbe895774e290da0 Reviewed-on: https://go-review.googlesource.com/18143 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
fa8384dfb9
commit
28b95edff2
|
|
@ -79,6 +79,15 @@ func goroutineLeaked() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// setParallel marks t as a parallel test if we're in short mode
|
||||
// (all.bash), but as a serial test otherwise. Using t.Parallel isn't
|
||||
// compatible with the afterTest func in non-short mode.
|
||||
func setParallel(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Parallel()
|
||||
}
|
||||
}
|
||||
|
||||
func afterTest(t testing.TB) {
|
||||
http.DefaultTransport.(*http.Transport).CloseIdleConnections()
|
||||
if testing.Short() {
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ func TestServerTimeouts(t *testing.T) {
|
|||
if runtime.GOOS == "plan9" {
|
||||
t.Skip("skipping test; see https://golang.org/issue/7237")
|
||||
}
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
reqNum := 0
|
||||
ts := httptest.NewUnstartedServer(HandlerFunc(func(res ResponseWriter, req *Request) {
|
||||
|
|
@ -939,7 +939,7 @@ func TestTLSHandshakeTimeout(t *testing.T) {
|
|||
if runtime.GOOS == "plan9" {
|
||||
t.Skip("skipping test; see https://golang.org/issue/7237")
|
||||
}
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {}))
|
||||
errc := make(chanWriter, 10) // but only expecting 1
|
||||
|
|
|
|||
|
|
@ -436,7 +436,7 @@ func TestTransportMaxPerHostIdleConns(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTransportServerClosingUnexpectedly(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
ts := httptest.NewServer(hostPortHandler)
|
||||
defer ts.Close()
|
||||
|
|
@ -969,7 +969,7 @@ func TestTransportGzipShort(t *testing.T) {
|
|||
|
||||
// tests that persistent goroutine connections shut down when no longer desired.
|
||||
func TestTransportPersistConnLeak(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
gotReqCh := make(chan bool)
|
||||
unblockCh := make(chan bool)
|
||||
|
|
@ -1036,7 +1036,7 @@ func TestTransportPersistConnLeak(t *testing.T) {
|
|||
// golang.org/issue/4531: Transport leaks goroutines when
|
||||
// request.ContentLength is explicitly short
|
||||
func TestTransportPersistConnLeakShortBody(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
}))
|
||||
|
|
@ -1377,7 +1377,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTransportResponseHeaderTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
if testing.Short() {
|
||||
t.Skip("skipping timeout test in -short mode")
|
||||
|
|
@ -1449,7 +1449,7 @@ func TestTransportResponseHeaderTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTransportCancelRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in -short mode")
|
||||
|
|
@ -1559,7 +1559,7 @@ Get = Get http://something.no-network.tld/: net/http: request canceled while wai
|
|||
}
|
||||
|
||||
func TestCancelRequestWithChannel(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in -short mode")
|
||||
|
|
@ -1617,7 +1617,7 @@ func TestCancelRequestWithChannel(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCancelRequestWithChannelBeforeDo(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
unblockc := make(chan bool)
|
||||
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
|
|
@ -2495,7 +2495,7 @@ func TestRetryIdempotentRequestsOnError(t *testing.T) {
|
|||
|
||||
// Issue 6981
|
||||
func TestTransportClosesBodyOnError(t *testing.T) {
|
||||
t.Parallel()
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
readBody := make(chan error, 1)
|
||||
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue