-
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.09% -0.20%
==========================================
Files 387 410 +23
Lines 38967 40389 +1422
==========================================
+ Hits 32066 33156 +1090
- Misses 5586 5863 +277
- Partials 1315 1370 +55 🚀 New features to boost your workflow:
|
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.
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. |
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 I had not published the earlier comments.
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 I had not published the earlier comments.
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.
LGTM
@dfawley for second review |
test/end2end_test.go
Outdated
// Tests to verify that client receive a cardinality violation error for | ||
// client-streaming RPCs if the server doesn't send a message before returning | ||
// status 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.
// Tests to verify that client receive a cardinality violation error for | |
// client-streaming RPCs if the server doesn't send a message before returning | |
// status OK. | |
// Tests that a client receives a cardinality violation error for | |
// client-streaming RPCs if the server doesn't send a message before returning | |
// status OK. |
(Please rewrap)
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.
Done.
test/end2end_test.go
Outdated
}) | ||
_, err := stream.Recv() | ||
if err == nil { | ||
logger.Fatalf("stream.Recv() = %v, want an error", err) |
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.
You want t.Errorf
not logger.Fatalf
here. logger.Fatalf
kills the whole process. t.Fatalf
kills the current goroutine. This won't run in the main test goroutine, so t.Fatalf
would just cause problems, not terminate the test.
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.
Right!
test/end2end_test.go
Outdated
}) | ||
_, err := stream.Recv() | ||
if err == nil { | ||
logger.Fatalf("stream.Recv() = %v, want an error", err) |
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: "= %v", err
-- err
is nil
. Just put nil
in the string.
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.
Done.
// Test to verify for client-streaming RPCs, when SendAndClose is called, the server | ||
// should reset stream after sending the response message successfully. |
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.
You don't appear to be validating RST_STREAM is written to the connection. You'll need to use the serverTester
for that.
test/end2end_test.go
Outdated
if status.Code(err) != codes.OK { | ||
t.Fatalf("stream.CloseAndRecv() = %v, want error %s", err, codes.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.
status.Code(nil)
is always codes.OK
so this doesn't do anything.
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.
Removed.
// TODO : https://github.com/grpc/grpc-go/issues/8119 - remove `t.Skip()` | ||
// after this is fixed. | ||
t.Skip() |
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.
Based on the test description above...why does this fail today? I don't think this should be a problem -- I was expecting that it's impossible for the server to do anything else.
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.
I am not sure what you mean , because if I send an error code , example Unimplemented
, according to the test , it is being reflected in the client when CloseAndRecv()
is called by client.
Also in the the code, SendAndCLose()
doesnt look like its doing anything to close , just calling SendMsg()
. It also says to return nil after calling SendAndCLose()
or return an error ,look here so I would think that returning an error after SendAndClose()
would surely propogate to client and this is the intended behavior and this test is not needed.
test/end2end_test.go
Outdated
sum := 0 | ||
in, _ := stream.Recv() | ||
p := in.GetPayload().GetBody() | ||
sum += len(p) |
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.
sum := len(p)
? But why is it a sum
? Probably this was left over from an old iteration. You can just delete it and return len(p)
directly in the response message, too. Or, better, just return 0 in the response. The value is unimportant.
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.
Done.
test/end2end_test.go
Outdated
payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, 1) | ||
if err != nil { | ||
t.Fatal(err) | ||
} |
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.
Seems easier to just delete this. Send empty requests instead...
Less code is usually better code.
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.
Done.
test/end2end_test.go
Outdated
select { | ||
case <-ctx.Done(): | ||
t.Fatal("timed out waiting for error from server") | ||
default: | ||
} |
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.
This can be replaced by doing:
for ctx.Err() == nil {
if err := stream.Send()....
}
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.
Done.
test/end2end_test.go
Outdated
} | ||
if err != nil { |
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.
If you use an else if
here, then you can use err :=
in the if
. That's more natural unless it's important to keep err
beyond the loop -- but it isn'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.
Done.
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