Skip to content

Commit

Permalink
net/http: deflake TestIdleConnH2Crash
Browse files Browse the repository at this point in the history
Fixes #17838

Change-Id: Ifafb4542a0ed6f2e29c9a83e30842e2fc18d6546
Reviewed-on: https://go-review.googlesource.com/33015
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Tom Bergan <[email protected]>
Reviewed-by: Michael Munday <[email protected]>
  • Loading branch information
bradfitz committed Nov 9, 2016
1 parent 22c70f2 commit 2f2b578
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/net/http/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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
}

Expand All @@ -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)
Expand Down

0 comments on commit 2f2b578

Please sign in to comment.