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

test: modify tests to use stubserver #7951

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

Conversation

pvsravani
Copy link
Contributor

Partially Addresses: #7291

RELEASE NOTES: None

@purnesh42H purnesh42H changed the title test: Modify tests to use stubserver instead of testservice test: modify tests to use stubserver instead of testservice Dec 23, 2024
@purnesh42H purnesh42H changed the title test: modify tests to use stubserver instead of testservice test: modify tests to use stubserver Dec 23, 2024
@purnesh42H purnesh42H self-assigned this Dec 24, 2024

testgrpc.RegisterTestServiceServer(s, ss)
defer ss.S.Stop()
stubserver.StartTestService(nil, ss)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you passing nil? You can pass t from caller and provide the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

go s.Serve(lis)
stubserver.StartTestService(nil, ss)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you passing nil? You can pass t from caller and provide the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.21%. Comparing base (724f450) to head (a82cae3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7951      +/-   ##
==========================================
+ Coverage   82.05%   82.21%   +0.15%     
==========================================
  Files         381      381              
  Lines       38539    38539              
==========================================
+ Hits        31622    31683      +61     
+ Misses       5602     5555      -47     
+ Partials     1315     1301      -14     

see 29 files with indirect coverage changes

defer s1.Stop()
ts := &funcServer{
unaryCall: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
//s1 := grpc.NewServer()
Copy link
Contributor

Choose a reason for hiding this comment

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

why are these commented out? They should be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

go s1.Serve(lis1)
stubserver.StartTestService(t, ss1)
defer ss1.S.Stop()
//testgrpc.RegisterTestServiceServer(s1, ts)
Copy link
Contributor

Choose a reason for hiding this comment

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

same. Please remove instead of commenting out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
t.Fatalf("Failed to create listener: %v", err)
}

ss := &stubserver.StubServer{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can be ss1 and then others can ss2, ss3 and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


conn2Established := grpcsync.NewEvent()
lis2, err := listenWithNotifyingListener("tcp", "localhost:0", conn2Established)
if err != nil {
t.Fatalf("Error while listening. Err: %v", err)
}
s2 := grpc.NewServer()
/*s2 := grpc.NewServer()
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

t.Errorf("unexpected error from send: %v", err)
return err
}
// Wait forever.
Copy link
Contributor

Choose a reason for hiding this comment

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

Its not wait forever. Its wait until a message is received from client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("net.Listen(tcp, localhost:0) failed: %v", err)
}
ss := &stubserver.StubServer{
EmptyCallF: func(_ context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

listener also needs to be assigned here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -162,18 +160,15 @@ func spoofDialer(addr net.Addr) func(target string, t time.Duration) (net.Conn,
}
}

func testLocalCredsE2EFail(dopts []grpc.DialOption) error {
func testLocalCredsE2EFail(t *testing.T, dopts []grpc.DialOption) error {
ss := &stubserver.StubServer{
EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same. Listener needs to be assigned here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

t.Log("Gracefully stopping server 1.")
go s1.GracefulStop()
go ss2.S.GracefulStop()
Copy link
Contributor

Choose a reason for hiding this comment

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

the comment says we are stopping server 1 and the change is stopping server 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -637,7 +653,7 @@ func (s) TestGoAwayThenClose(t *testing.T) {
lis2.Close()

t.Log("Hard closing connection 1.")
s1.Stop()
ss2.S.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -40,8 +40,14 @@ import (
testpb "google.golang.org/grpc/interop/grpc_testing"
)

func testLocalCredsE2ESucceed(network, address string) error {
func testLocalCredsE2ESucceed(t *testing.T, network, address string) error {

Copy link
Contributor

Choose a reason for hiding this comment

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

nix new line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

go s.Serve(lis)

ss1 := &stubserver.StubServer{
Listener: lis,
Copy link
Contributor

Choose a reason for hiding this comment

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

let's do the same with listeners to be consistent. lis1, lis2, lis3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

s2 := grpc.NewServer()
defer s2.Stop()
testgrpc.RegisterTestServiceServer(s2, ts)
ss3 := &stubserver.StubServer{
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you create ss3? I don't think its used anywhere. The existing test only has 2 servers and 2 listeners

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

Successfully merging this pull request may close these issues.

2 participants