Skip to content

Commit 2f2b578

Browse files
committed
net/http: deflake TestIdleConnH2Crash
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]>
1 parent 22c70f2 commit 2f2b578

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/net/http/transport_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,12 +3667,12 @@ func TestIdleConnH2Crash(t *testing.T) {
36673667
ctx, cancel := context.WithCancel(context.Background())
36683668
defer cancel()
36693669

3670-
gotErr := make(chan bool, 1)
3670+
sawDoErr := make(chan bool, 1)
3671+
testDone := make(chan struct{})
3672+
defer close(testDone)
36713673

36723674
cst.tr.IdleConnTimeout = 5 * time.Millisecond
36733675
cst.tr.DialTLS = func(network, addr string) (net.Conn, error) {
3674-
cancel()
3675-
<-gotErr
36763676
c, err := tls.Dial(network, addr, &tls.Config{
36773677
InsecureSkipVerify: true,
36783678
NextProtos: []string{"h2"},
@@ -3686,6 +3686,17 @@ func TestIdleConnH2Crash(t *testing.T) {
36863686
c.Close()
36873687
return nil, errors.New("bogus")
36883688
}
3689+
3690+
cancel()
3691+
3692+
failTimer := time.NewTimer(5 * time.Second)
3693+
defer failTimer.Stop()
3694+
select {
3695+
case <-sawDoErr:
3696+
case <-testDone:
3697+
case <-failTimer.C:
3698+
t.Error("timeout in DialTLS, waiting too long for cst.c.Do to fail")
3699+
}
36893700
return c, nil
36903701
}
36913702

@@ -3696,7 +3707,7 @@ func TestIdleConnH2Crash(t *testing.T) {
36963707
res.Body.Close()
36973708
t.Fatal("unexpected success")
36983709
}
3699-
gotErr <- true
3710+
sawDoErr <- true
37003711

37013712
// Wait for the explosion.
37023713
time.Sleep(cst.tr.IdleConnTimeout * 10)

0 commit comments

Comments
 (0)