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

grpc_test: add tests for cardinality violation #8120

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

eshitachandwani
Copy link
Member

Fixes: #7570

Added tests for cardinality violations :

  1. Client should ensure a status internal error is returned for client-streaming RPCs if the server doesn't send a message before returning status OK.
  2. Also for client-streaming RPCs, when 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

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.09%. Comparing base (ae2a04f) to head (a953b40).
Report is 55 commits behind head on master.

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     

see 103 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 148 to 149
earlyNil bool // whether to return nil without calling SendAndClose().
recvAfterClose bool // whether to call Recv() after calling SendAndClose().
Copy link
Member

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:

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!

@dfawley dfawley assigned eshitachandwani and unassigned dfawley Feb 27, 2025
Copy link
Contributor

@purnesh42H purnesh42H left a 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.

@purnesh42H purnesh42H removed their assignment Mar 4, 2025
@eshitachandwani
Copy link
Member Author

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 TestClientStreamingRecvAfterCloseError test , can you tell me what is the difference between the two?

@purnesh42H
Copy link
Contributor

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 TestClientStreamingRecvAfterCloseError test , can you tell me what is the difference between the two?

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.

Copy link
Member Author

@eshitachandwani eshitachandwani left a 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.

Copy link
Member Author

@eshitachandwani eshitachandwani left a 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.

Copy link
Contributor

@purnesh42H purnesh42H left a comment

Choose a reason for hiding this comment

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

LGTM

@purnesh42H purnesh42H requested a review from dfawley April 1, 2025 17:15
@purnesh42H purnesh42H assigned dfawley and unassigned purnesh42H Apr 1, 2025
@purnesh42H
Copy link
Contributor

@dfawley for second review

Comment on lines 3589 to 3591
// 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

})
_, err := stream.Recv()
if err == nil {
logger.Fatalf("stream.Recv() = %v, want an error", err)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right!

})
_, err := stream.Recv()
if err == nil {
logger.Fatalf("stream.Recv() = %v, want an error", err)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +3623 to +3624
// Test to verify for client-streaming RPCs, when SendAndClose is called, the server
// should reset stream after sending the response message successfully.
Copy link
Member

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.

Comment on lines 3681 to 3683
if status.Code(err) != codes.OK {
t.Fatalf("stream.CloseAndRecv() = %v, want error %s", err, codes.OK)
}
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.

Comment on lines +3690 to +3692
// TODO : https://github.com/grpc/grpc-go/issues/8119 - remove `t.Skip()`
// after this is fixed.
t.Skip()
Copy link
Member

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.

Copy link
Member Author

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.

sum := 0
in, _ := stream.Recv()
p := in.GetPayload().GetBody()
sum += len(p)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 3717 to 3720
payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, 1)
if err != nil {
t.Fatal(err)
}
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 3733 to 3737
select {
case <-ctx.Done():
t.Fatal("timed out waiting for error from server")
default:
}
Copy link
Member

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()....
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 3729 to 3730
}
if err != nil {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants