Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose public creation methods for GRPCAsyncRequestStream and GRPCAsyncResponseStreamWriter #1485

Merged
merged 6 commits into from
Sep 22, 2022

Conversation

FranzBusch
Copy link
Collaborator

Motivation

It is highly desirable to be able to write tests against the generated method of a service. Currently, this is close to impossible since both the GRPCAsyncRequestStream and the GRPCAsyncResponseStreamWriter don't expose a public init so users cannot drive and observe the functions.

Modification

Adds new public methods to drive and observe the request stream and the response writer.

Result

We can now properly test gRPC generated server function implementations.

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Maybe I'm a bit lost, but what's the intended use of RecordingWriter?

@FranzBusch
Copy link
Collaborator Author

Maybe I'm a bit lost, but what's the intended use of RecordingWriter?

Sure, maybe I should have put more context in the description. The problem that we have at the moment is that if you implement a method that writing a stream of responses and subsequently you want to write a test for your implementation then you really can't do this since you can't instantiate GRPCAsyncResponseStreamWriter. Furthermore, even if you can you want to actually assert which responses you wrote.

The goal of this PR is to make it possible to write unit tests for implementation of generated protocol methods. More specifically for the methods that have either request/response streams.

@Lukasa
Copy link
Collaborator

Lukasa commented Sep 16, 2022

Ok, that makes sense. Can you provide this as a detailed doc comment on the type? It'll make it much easier for users to discover the intended use of this object.

/// This struct contains two properties:
/// 1. The ``writer`` which is the actual ``GRPCAsyncResponseStreamWriter`` and should be passed to the method under testing.
/// 2. The ``stream`` which can be used to observe the written responses.
public struct ResponseStreamWriter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make the naming a little clearer that it's for testing? The names on the request side are 👌

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah slightly awkward naming these types. I ended up with TestingStreamWriter and makeTestingResponseStreamWriter() which aligns with the request side

…nseStreamWriter`

# Motivation
It is highly desirable to be able to write tests against the generated method of a service. Currently, this is close to impossible since both the `GRPCAsyncRequestStream` and the `GRPCAsyncResponseStreamWriter` don't expose a public init so users cannot drive and observe the functions.

# Modification
Adds new public methods to drive and observe the request stream and the response writer.

# Result
We can now properly test gRPC generated server function implementations.
@glbrntt glbrntt merged commit b11a856 into grpc:main Sep 22, 2022
WendellXY pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
…AsyncResponseStreamWriter` (grpc#1485)

Motivation:

It is highly desirable to be able to write tests against the generated method of a service. Currently, this is close to impossible since both the `GRPCAsyncRequestStream` and the `GRPCAsyncResponseStreamWriter` don't expose a public init so users cannot drive and observe the functions.

Modification:

Adds new public methods to drive and observe the request stream and the response writer.

Result

We can now test functions which use the request stream and response stream writer.
pinlin168 pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
…AsyncResponseStreamWriter` (grpc#1485)

Motivation:

It is highly desirable to be able to write tests against the generated method of a service. Currently, this is close to impossible since both the `GRPCAsyncRequestStream` and the `GRPCAsyncResponseStreamWriter` don't expose a public init so users cannot drive and observe the functions.

Modification:

Adds new public methods to drive and observe the request stream and the response writer.

Result

We can now test functions which use the request stream and response stream writer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor ↑ Requires a SemVer Minor version change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants