Skip to content

Commit

Permalink
http2: remove race from TestTransportCancelDataResponseRace
Browse files Browse the repository at this point in the history
Wait for the client request to return before cancelling the request.
Then cancel the request and send more data.

Fixes: golang/go#45701

Change-Id: Icc81f9c6fefdda1d978e6234c9894f552daecd45
Reviewed-on: https://go-review.googlesource.com/c/net/+/320369
Run-TryBot: Bryan Mills <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Auto-Submit: Damien Neil <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
  • Loading branch information
fraenkel authored and neild committed Sep 21, 2022
1 parent 1e53447 commit 8328fa1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions http2/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3412,7 +3412,7 @@ func TestClientConnPing(t *testing.T) {
// connection.
func TestTransportCancelDataResponseRace(t *testing.T) {
cancel := make(chan struct{})
clientGotError := make(chan bool, 1)
clientGotResponse := make(chan bool, 1)

const msg = "Hello."
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -3425,8 +3425,8 @@ func TestTransportCancelDataResponseRace(t *testing.T) {
io.WriteString(w, "Some data.")
w.(http.Flusher).Flush()
if i == 2 {
<-clientGotResponse
close(cancel)
<-clientGotError
}
time.Sleep(10 * time.Millisecond)
}
Expand All @@ -3440,13 +3440,13 @@ func TestTransportCancelDataResponseRace(t *testing.T) {
req, _ := http.NewRequest("GET", st.ts.URL, nil)
req.Cancel = cancel
res, err := c.Do(req)
clientGotResponse <- true
if err != nil {
t.Fatal(err)
}
if _, err = io.Copy(ioutil.Discard, res.Body); err == nil {
t.Fatal("unexpected success")
}
clientGotError <- true

res, err = c.Get(st.ts.URL + "/hello")
if err != nil {
Expand Down

0 comments on commit 8328fa1

Please sign in to comment.