Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions test/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ func (s) TestRSTDuringMessageRead(t *testing.T) {
t.Errorf("Error while writing settings: %v", err)
return
}
var mu sync.Mutex
for {
for ctx.Err() == nil {
frame, err := framer.ReadFrame()
if err != nil {
return
Expand All @@ -209,27 +208,14 @@ func (s) TestRSTDuringMessageRead(t *testing.T) {
case *http2.HeadersFrame:
// When the client creates a stream, write a partial gRPC
// message followed by an RST_STREAM.
go func() {
buf := make([]byte, 1024)
// Write the gRPC message length header.
binary.BigEndian.PutUint32(buf[1:5], 2048)
mu.Lock()
if err := framer.WriteData(1, false, buf); err != nil {
mu.Unlock()
return
}
framer.WriteRSTStream(1, http2.ErrCodeCancel)
mu.Unlock()
}()
case *http2.RSTStreamFrame:
if frame.Header().StreamID != 1 || http2.ErrCode(frame.ErrCode) != http2.ErrCodeFlowControl {
t.Errorf("RST stream received with streamID: %d and code: %v, want streamID: 1 and code: http2.ErrCodeFlowControl", frame.Header().StreamID, http2.ErrCode(frame.ErrCode))
messageLen := 2048

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

buf := make([]byte, messageLen/2)
// Write the gRPC message length header.
binary.BigEndian.PutUint32(buf[1:5], uint32(messageLen))
if err := framer.WriteData(1, false, buf); err != nil {
return
}
return
case *http2.PingFrame:
mu.Lock()
framer.WritePing(true, frame.Data)
mu.Unlock()
framer.WriteRSTStream(1, http2.ErrCodeCancel)
default:
t.Logf("Server received frame: %v", frame)
}
Expand All @@ -239,13 +225,7 @@ func (s) TestRSTDuringMessageRead(t *testing.T) {
// The server will send a partial gRPC message before cancelling the stream.
// The client should get a gRPC status with code CANCELLED.
client := testgrpc.NewTestServiceClient(cc)
_, err = client.EmptyCall(ctx, &testpb.Empty{})

s, ok := status.FromError(err)
if !ok {
t.Fatalf("client.EmptyCall() returned non-status error: %v", err)
}
if s.Code() != codes.Canceled {
t.Fatalf("client.EmptyCall() returned status %v with code %v, want %v", s, s.Code(), codes.Canceled)
if _, err := client.EmptyCall(ctx, &testpb.Empty{}); status.Code(err) != codes.Canceled {
t.Fatalf("client.EmptyCall() returned %v; want status with code %v", err, codes.Canceled)
}
}