Skip to content

Mock a stream without implying an io.EOF return #167

@seanlafferty-ibm

Description

@seanlafferty-ibm

I'm mocking a server with MockServerWithBufConn, and I'm trying to mock a grpc client stream like so

server.ExpectClientStream(myMethodName).Once().Return(myResponse)

however when my app code calls Send() on the stream, it gets back an io.EOF error. Looking through the source code I think this is happening because the underlying bufconn only has one message in the queue, and once there's none left it sends an io.EOF. Im looking for a way to return a nil error instead, as I want to replicate what happens with a real server with a long-lived connection.

Said simply, I looking to to mock a stream response, without also implying the server is terminating the connection.

I tried using Run() instead like

server.ExpectClientStream(myMethodName).Once().Run(func(ctx context.Context, s grpc.ServerStream) (any, error) {
  sends := 1
  for sends <= 2 {
    sends++
    // s.Recv()
    // s.Send()
  }
})

which fixes the app seeing an io.EOF, but ultimately causes other issues since Im only calling Send() once in the application code, not twice.

Does this make sense, or do I have a misunderstanding in how I should be stringing these mocks together?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions