fix a race in transport_test.go

This commit is contained in:
iamqizhao
2015-04-03 17:53:58 -07:00
parent fba61d1bde
commit 9dd6a107d8

View File

@ -430,12 +430,22 @@ func TestServerWithMisbehavedClient(t *testing.T) {
Method: "foo", Method: "foo",
} }
var sc *http2Server var sc *http2Server
for k, _ := range server.conns { // Wait until the server transport is setup.
var ok bool for {
sc, ok = k.(*http2Server) server.mu.Lock()
if !ok { if len(server.conns) > 0 {
t.Fatalf("Failed to convert %v to *http2Server", k) for k, _ := range server.conns {
var ok bool
sc, ok = k.(*http2Server)
if !ok {
t.Fatalf("Failed to convert %v to *http2Server", k)
}
}
server.mu.Unlock()
break
} }
server.mu.Unlock()
time.Sleep(time.Millisecond)
} }
cc, ok := ct.(*http2Client) cc, ok := ct.(*http2Client)
if !ok { if !ok {
@ -454,17 +464,23 @@ func TestServerWithMisbehavedClient(t *testing.T) {
} }
cc.writableChan <- 0 cc.writableChan <- 0
sent += http2MaxFrameLen sent += http2MaxFrameLen
// Wait until the server creates the corresponding stream. // Wait until the server creates the corresponding stream and receive some data.
var ss *Stream var ss *Stream
for { for {
time.Sleep(time.Millisecond) time.Sleep(time.Millisecond)
sc.mu.Lock() sc.mu.Lock()
if len(sc.activeStreams) > 0 { if len(sc.activeStreams) == 0 {
ss = sc.activeStreams[s.id]
sc.mu.Unlock() sc.mu.Unlock()
continue
}
ss = sc.activeStreams[s.id]
sc.mu.Unlock()
ss.fc.mu.Lock()
if ss.fc.pendingData > 0 {
ss.fc.mu.Unlock()
break break
} }
sc.mu.Unlock() ss.fc.mu.Unlock()
} }
if ss.fc.pendingData != http2MaxFrameLen || ss.fc.pendingUpdate != 0 || sc.fc.pendingData != http2MaxFrameLen || sc.fc.pendingUpdate != 0 { if ss.fc.pendingData != http2MaxFrameLen || ss.fc.pendingUpdate != 0 || sc.fc.pendingData != http2MaxFrameLen || sc.fc.pendingUpdate != 0 {
t.Fatalf("Server mistakenly updates inbound flow control params: got %d, %d, %d, %d; want %d, %d, %d, %d", ss.fc.pendingData, ss.fc.pendingUpdate, sc.fc.pendingData, sc.fc.pendingUpdate, http2MaxFrameLen, 0, http2MaxFrameLen, 0) t.Fatalf("Server mistakenly updates inbound flow control params: got %d, %d, %d, %d; want %d, %d, %d, %d", ss.fc.pendingData, ss.fc.pendingUpdate, sc.fc.pendingData, sc.fc.pendingUpdate, http2MaxFrameLen, 0, http2MaxFrameLen, 0)