fix a race in transport_test.go
This commit is contained in:
@ -430,6 +430,10 @@ func TestServerWithMisbehavedClient(t *testing.T) {
|
|||||||
Method: "foo",
|
Method: "foo",
|
||||||
}
|
}
|
||||||
var sc *http2Server
|
var sc *http2Server
|
||||||
|
// Wait until the server transport is setup.
|
||||||
|
for {
|
||||||
|
server.mu.Lock()
|
||||||
|
if len(server.conns) > 0 {
|
||||||
for k, _ := range server.conns {
|
for k, _ := range server.conns {
|
||||||
var ok bool
|
var ok bool
|
||||||
sc, ok = k.(*http2Server)
|
sc, ok = k.(*http2Server)
|
||||||
@ -437,6 +441,12 @@ func TestServerWithMisbehavedClient(t *testing.T) {
|
|||||||
t.Fatalf("Failed to convert %v to *http2Server", k)
|
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 {
|
||||||
t.Fatalf("Failed to convert %v to *http2Client", ct)
|
t.Fatalf("Failed to convert %v to *http2Client", ct)
|
||||||
@ -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 {
|
||||||
|
sc.mu.Unlock()
|
||||||
|
continue
|
||||||
|
}
|
||||||
ss = sc.activeStreams[s.id]
|
ss = sc.activeStreams[s.id]
|
||||||
sc.mu.Unlock()
|
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)
|
||||||
|
Reference in New Issue
Block a user