浏览代码

http2: fix racey and flaky server push test

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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Tom Bergan 9 年之前
父节点
当前提交
e36fcd2311
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      http2/server_push_test.go

+ 9 - 4
http2/server_push_test.go

@@ -14,6 +14,7 @@ import (
 	"net/http"
 	"reflect"
 	"strconv"
+	"sync"
 	"testing"
 	"time"
 )
@@ -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) {
@@ -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) })
 				}
 			}
 		}