Skip to content

Commit

Permalink
http2: fix racey and flaky server push test
Browse files Browse the repository at this point in the history
The bad test was added in https://go-review.googlesource.com/32887.
My fault.

Change-Id: Iee98ef0579bc5de086fa286530d45db009407d10
Reviewed-on: https://go-review.googlesource.com/32910
Reviewed-by: Brad Fitzpatrick <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
tombergan authored and bradfitz committed Nov 8, 2016
1 parent 87635b2 commit e36fcd2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions http2/server_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"reflect"
"strconv"
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -429,6 +430,7 @@ func TestServer_Push_StateTransitions(t *testing.T) {
}

func TestServer_Push_RejectAfterGoAway(t *testing.T) {
var readyOnce sync.Once
ready := make(chan struct{})
errc := make(chan error, 2)
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -449,12 +451,15 @@ func TestServer_Push_RejectAfterGoAway(t *testing.T) {
// Send GOAWAY and wait for it to be processed.
st.fr.WriteGoAway(1, ErrCodeNo, nil)
go func() {
done := false
for !done {
for {
select {
case <-ready:
return
default:
}
st.sc.testHookCh <- func(loopNum int) {
if !st.sc.pushEnabled {
close(ready)
done = true
readyOnce.Do(func() { close(ready) })
}
}
}
Expand Down

0 comments on commit e36fcd2

Please sign in to comment.