Skip to content

Commit

Permalink
Clarify purpose of handler_stream_test.go (#472)
Browse files Browse the repository at this point in the history
Clarify that the sole purpose of the test in `handler_stream_test.go` is
to verify a safety property of the `ClientStream` iterator. A similar
testing strategy isn't worthwhile for `ServerStream` or `BidiStream`,
because they're not iterators.

---------

Co-authored-by: Akshay Shah <akshay@akshayshah.org>
  • Loading branch information
Hirochon and akshayjshah authored Mar 6, 2023
1 parent 8dadf11 commit e523571
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions handler_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ import (
pingv1 "connectrpc.com/connect/internal/gen/connect/ping/v1"
)

func TestClientStream(t *testing.T) {
func TestClientStreamIterator(t *testing.T) {
t.Parallel()
// The server's view of a client streaming RPC is an iterator. For safety,
// and to match grpc-go's behavior, we should allocate a new message for each
// iteration.
stream := &ClientStream[pingv1.PingRequest]{conn: &nopStreamingHandlerConn{}}
assert.True(t, stream.Receive())
first := fmt.Sprintf("%p", stream.Msg())
assert.True(t, stream.Receive())
second := fmt.Sprintf("%p", stream.Msg())
assert.NotEqual(t, first, second)
assert.NotEqual(t, first, second, assert.Sprintf("should allocate a new message for each iteration"))
}

type nopStreamingHandlerConn struct {
Expand Down

0 comments on commit e523571

Please sign in to comment.