1
0
mirror of https://github.com/golang/go synced 2024-11-12 05:40:22 -07:00

net/http: deflake TestIdleConnH2Crash

Fixes #17838

Change-Id: Ifafb4542a0ed6f2e29c9a83e30842e2fc18d6546
Reviewed-on: https://go-review.googlesource.com/33015
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tom Bergan <tombergan@google.com>
Reviewed-by: Michael Munday <munday@ca.ibm.com>
This commit is contained in:
Brad Fitzpatrick 2016-11-09 21:35:37 +00:00
parent 22c70f268b
commit 2f2b57853e

View File

@ -3667,12 +3667,12 @@ func TestIdleConnH2Crash(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
gotErr := make(chan bool, 1)
sawDoErr := make(chan bool, 1)
testDone := make(chan struct{})
defer close(testDone)
cst.tr.IdleConnTimeout = 5 * time.Millisecond
cst.tr.DialTLS = func(network, addr string) (net.Conn, error) {
cancel()
<-gotErr
c, err := tls.Dial(network, addr, &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{"h2"},
@ -3686,6 +3686,17 @@ func TestIdleConnH2Crash(t *testing.T) {
c.Close()
return nil, errors.New("bogus")
}
cancel()
failTimer := time.NewTimer(5 * time.Second)
defer failTimer.Stop()
select {
case <-sawDoErr:
case <-testDone:
case <-failTimer.C:
t.Error("timeout in DialTLS, waiting too long for cst.c.Do to fail")
}
return c, nil
}
@ -3696,7 +3707,7 @@ func TestIdleConnH2Crash(t *testing.T) {
res.Body.Close()
t.Fatal("unexpected success")
}
gotErr <- true
sawDoErr <- true
// Wait for the explosion.
time.Sleep(cst.tr.IdleConnTimeout * 10)