-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
grpc_test: add tests for cardinality violation #8120
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8120 +/- ##
==========================================
+ Coverage 82.29% 82.34% +0.05%
==========================================
Files 387 389 +2
Lines 38967 39103 +136
==========================================
+ Hits 32066 32201 +135
- Misses 5586 5588 +2
+ Partials 1315 1314 -1 |
test/end2end_test.go
Outdated
earlyNil bool // whether to return nil without calling SendAndClose(). | ||
recvAfterClose bool // whether to call Recv() after calling SendAndClose(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really really don't want to extend testServer
. Could you use the stubserver
package instead? testServer
has a lot of bad properties (especially: it splits the testing code into two different places: the test and the testServer
), and this only complicates it further by adding more ways to conditionalize its behavior.
You can follow this kind of example to use stubserver
instead:
Line 4485 in d48317f
ss := &stubserver.StubServer{ |
Also please add a comment on testServer
that it should not be used for any new tests so that this doesn't happen again.
Sorry!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we need one more test case when "Server Doesn't RST_STREAM"
Server-Side:
- Create a client-streaming RPC handler.
- The handler calls SendAndClose with a valid response message.
- The handler then attempts to call Recv.
Client-Side:
- Make a client-streaming RPC call.
- Continuously send messages.
Expected Outcome:
- The server's Recv call should return an error indicating that the stream is closed.
- The client's Send calls should eventually return an error indicating that the stream has been reset.
@@ -3585,6 +3586,90 @@ func testClientStreamingError(t *testing.T, e env) { | |||
} | |||
} | |||
|
|||
func (s) TestClientStreamingMissingSendAndCloseError(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add docstring for this explaining what its verifying i.e. what is the expected behavior
testClientStreamingRecvAfterCloseError(t) | ||
} | ||
|
||
func testClientStreamingRecvAfterCloseError(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add docstring for this explaining what its verifying i.e. what is the expected behavior
// TODO : https://github.com/grpc/grpc-go/issues/8119 - remove `t.Skip()` | ||
// after this is fixed. | ||
t.Skip() | ||
testClientStreamingMissingSendAndCloseError(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are moving the test logic to helper? Can't we just write within this test?
t.Fatalf(".StreamingInputCall(_) = _, %v, want <nil>", err) | ||
} | ||
|
||
if _, err := stream.CloseAndRecv(); status.Code(err) != codes.Internal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Client streaming RPCs must terminate with either no message and a non-OK status, or a message and an OK status.
Based on #7570, since we are not sending message from handler, i think we need to verify if we are getting the error and the status
is not-ok
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in this case, we should receive Error log messages indicating what happened and that it is illegal behavior.
how do we verify this? I think there are some existing tests which parse the error logs and verify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it might be good to have separate if condition for both error and status violation. Although they are always supposed to happen in conjuction but checking them separately make it easier to understand.
if _, err := stream.CloseAndRecv(); err == nil {
t.Fatalf("CloseAndRecv should have returned an error")
}
if status.Code(err) == status.ok {
t.Fatalf("CloseAndRecv should have returned a non-ok")
}
@@ -3585,6 +3586,90 @@ func testClientStreamingError(t *testing.T, e env) { | |||
} | |||
} | |||
|
|||
func (s) TestClientStreamingMissingSendAndCloseError(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion for name to be more explicit TestClientStreamingCardinalityViolation_ServerHandlerMissingSendAndClose
} | ||
} | ||
|
||
func (s) TestClientStreamingRecvAfterCloseError(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion for name to be more explicit TestClientStreamingCardinalityViolation_IgnoreServerHandlerErrorAfterSendAndClose
stream.SendAndClose(&testpb.StreamingInputCallResponse{ | ||
AggregatedPayloadSize: int32(sum), | ||
}) | ||
_, err := stream.Recv() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: do we need to do this? What if just return a static error with status code like status.Error(codes.Internal, "something went wrong")).
? Because calling stream.Recv() adding one more possibility to the test case
if err = stream.Send(req); err == nil { | ||
continue | ||
} | ||
if _, err := stream.CloseAndRecv(); status.Code(err) != codes.Internal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We should probably just break out of loop when server closes the stream and call the CloseAndRecv() outside
continue | ||
} | ||
if _, err := stream.CloseAndRecv(); status.Code(err) != codes.Internal { | ||
t.Fatalf("%v.CloseAndRecv() = %v, want error %s", stream, err, codes.Internal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment here as above, probably good to write 2 separate ifs but the opposite way in this case. 1) raise t.Fatalf if error is not nil. 2) raise t.Fatalf if status is not ok
This looks like the test I have written already , the |
yeah looks close. I think the for loop is not clear. We should do t.LogF when receiving error from client.Send indicating rst_stream. Is it possible to verify if rst stream was received in trailers. If its too complicated we can skip but let's see if we can. Other thing is the for loop shouldn't be indefinite. We should also do t.Fatalf if context is done. That way its clear that we are expecting an error for this test. Having said that, then I think then we need a separate test case where client ignores the error after SendAndClose. It will slightly shorter where the handler return a static error and client just ignores it and status is ok. |
Fixes: #7570
Added tests for cardinality violations :
internal
error is returned for client-streaming RPCs if the server doesn't send a message before returning status OK.SendAndClose
is called, the server should perform a RST_STREAM() after sending the response message successfully.Skipping the tests for now till the issues are fixed: #8119
RELEASE NOTES: N/A