Skip to content

Commit

Permalink
http2: eliminate arbitrary timeouts in testServerResponse
Browse files Browse the repository at this point in the history
If the test deadlocks, we probably want a goroutine dump (which will
happen naturally if we allow the test to time out). Otherwise, these
arbitrary timeouts tend to only add noise on slower builders.

Fixes golang/go#53160 (maybe).

Change-Id: I2a95bf7fece27f949ab2cf9dea36fe440ac90d51
Reviewed-on: https://go-review.googlesource.com/c/net/+/409574
Reviewed-by: Damien Neil <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed May 31, 2022
1 parent 367de7d commit 1855be7
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2646,8 +2646,7 @@ func (st *serverTester) decodeHeader(headerBlock []byte) (pairs [][2]string) {
}

// testServerResponse sets up an idle HTTP/2 connection. The client function should
// write a single request that must be handled by the handler. This waits up to 5s
// for client to return, then up to an additional 2s for the handler to return.
// write a single request that must be handled by the handler.
func testServerResponse(t testing.TB,
handler func(http.ResponseWriter, *http.Request) error,
client func(*serverTester),
Expand All @@ -2657,30 +2656,20 @@ func testServerResponse(t testing.TB,
if r.Body == nil {
t.Fatal("nil Body")
}
errc <- handler(w, r)
err := handler(w, r)
select {
case errc <- err:
default:
t.Errorf("unexpected duplicate request")
}
})
defer st.Close()

donec := make(chan bool)
go func() {
defer close(donec)
st.greet()
client(st)
}()

select {
case <-donec:
case <-time.After(5 * time.Second):
t.Fatal("timeout in client")
}
st.greet()
client(st)

select {
case err := <-errc:
if err != nil {
t.Fatalf("Error in handler: %v", err)
}
case <-time.After(2 * time.Second):
t.Fatal("timeout in handler")
if err := <-errc; err != nil {
t.Fatalf("Error in handler: %v", err)
}
}

Expand Down

0 comments on commit 1855be7

Please sign in to comment.