Skip to content

Commit 336fc1b

Browse files
committed
Add integration test to reproduce issue with empty payloads
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent baadfd8 commit 336fc1b

4 files changed

Lines changed: 122 additions & 14 deletions

File tree

integration/streaming/test.pb.go

Lines changed: 22 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/streaming/test.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ service Streaming {
3434
rpc DivideStream(Sum) returns (stream Part);
3535
rpc EchoNull(stream EchoPayload) returns (google.protobuf.Empty);
3636
rpc EchoNullStream(stream EchoPayload) returns (stream google.protobuf.Empty);
37+
rpc EmptyPayloadStream(google.protobuf.Empty) returns (stream EchoPayload);
3738
}
3839

3940
message EchoPayload {

integration/streaming/test_ttrpc.pb.go

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/streaming_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/containerd/ttrpc"
3232
"github.com/containerd/ttrpc/integration/streaming"
3333
"github.com/golang/protobuf/ptypes/empty"
34+
"google.golang.org/protobuf/types/known/emptypb"
3435
)
3536

3637
func runService(ctx context.Context, t testing.TB, service streaming.TTRPCStreamingService) (streaming.TTRPCStreamingClient, func()) {
@@ -190,6 +191,18 @@ func (tss *testStreamingService) EchoNullStream(_ context.Context, es streaming.
190191
return sendErr
191192
}
192193

194+
func (tss *testStreamingService) EmptyPayloadStream(_ context.Context, _ *emptypb.Empty, streamer streaming.TTRPCStreaming_EmptyPayloadStreamServer) error {
195+
if err := streamer.Send(&streaming.EchoPayload{Seq: 1}); err != nil {
196+
return err
197+
}
198+
199+
if err := streamer.Send(&streaming.EchoPayload{Seq: 2}); err != nil {
200+
return err
201+
}
202+
203+
return nil
204+
}
205+
193206
func TestStreamingService(t *testing.T) {
194207
ctx, cancel := context.WithCancel(context.Background())
195208
defer cancel()
@@ -203,6 +216,7 @@ func TestStreamingService(t *testing.T) {
203216
t.Run("DivideStream", divideStreamTest(ctx, client))
204217
t.Run("EchoNull", echoNullTest(ctx, client))
205218
t.Run("EchoNullStream", echoNullStreamTest(ctx, client))
219+
t.Run("EmptyPayloadStream", emptyPayloadStream(ctx, client))
206220
}
207221

208222
func echoTest(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
@@ -385,6 +399,36 @@ func echoNullStreamTest(ctx context.Context, client streaming.TTRPCStreamingClie
385399
}
386400
}
387401

402+
func emptyPayloadStream(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
403+
return func(t *testing.T) {
404+
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
405+
defer cancel()
406+
407+
stream, err := client.EmptyPayloadStream(ctx, nil)
408+
if err != nil {
409+
t.Fatal(err)
410+
}
411+
412+
for i := uint32(1); i < 3; i++ {
413+
first, err := stream.Recv()
414+
if err != nil {
415+
t.Fatal(err)
416+
}
417+
418+
if first.Seq != i {
419+
t.Fatalf("unexpected seq: %d != %d", first.Seq, i)
420+
}
421+
}
422+
423+
if err := stream.CloseSend(); err != nil {
424+
t.Fatal(err)
425+
}
426+
if _, err := stream.Recv(); err != io.EOF {
427+
t.Fatalf("Expected io.EOF, got %v", err)
428+
}
429+
}
430+
}
431+
388432
func assertNextEcho(t testing.TB, a, b *streaming.EchoPayload) {
389433
t.Helper()
390434
if a.Msg != b.Msg {

0 commit comments

Comments
 (0)