net/http: add mechanism for marking flaky http tests

This shouldn't need to exist in general, but in practice I want something
like this a few times per year.

Change-Id: I9c220e58be44b7726f75d776f714212c570cf8bb
Reviewed-on: https://go-review.googlesource.com/18286
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Brad Fitzpatrick 2016-01-06 19:19:39 +00:00
parent 4391aca850
commit af768fdd34
2 changed files with 10 additions and 1 deletions

View File

@ -5,6 +5,7 @@
package http_test
import (
"flag"
"fmt"
"net/http"
"os"
@ -15,6 +16,8 @@ import (
"time"
)
var flaky = flag.Bool("flaky", false, "run known-flaky tests too")
func TestMain(m *testing.M) {
v := m.Run()
if v == 0 && goroutineLeaked() {
@ -88,6 +91,12 @@ func setParallel(t *testing.T) {
}
}
func setFlaky(t *testing.T, issue int) {
if !*flaky {
t.Skipf("skipping known flaky test; see golang.org/issue/%d", issue)
}
}
func afterTest(t testing.TB) {
http.DefaultTransport.(*http.Transport).CloseIdleConnections()
if testing.Short() {

View File

@ -1649,7 +1649,7 @@ func TestCancelRequestWithChannelBeforeDo(t *testing.T) {
// Issue 11020. The returned error message should be errRequestCanceled
func TestTransportCancelBeforeResponseHeaders(t *testing.T) {
t.Skip("Skipping flaky test; see Issue 11894")
setFlaky(t, 11894)
defer afterTest(t)
serverConnCh := make(chan net.Conn, 1)