-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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/gracefulstop: use stubserver instead of testservice implementation #7907
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 #7907 +/- ##
==========================================
- Coverage 82.04% 82.02% -0.03%
==========================================
Files 377 381 +4
Lines 38180 38539 +359
==========================================
+ Hits 31326 31610 +284
- Misses 5551 5606 +55
- Partials 1303 1323 +20 |
test/gracefulstop_test.go
Outdated
@@ -122,7 +122,8 @@ func (s) TestGracefulStop(t *testing.T) { | |||
}, | |||
} | |||
s := grpc.NewServer() | |||
testgrpc.RegisterTestServiceServer(s, ss) | |||
ss.S = s |
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 think you have to assign the listener as well when creating the stub server?
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/gracefulstop_test.go
Outdated
@@ -122,7 +122,8 @@ func (s) TestGracefulStop(t *testing.T) { | |||
}, | |||
} | |||
s := grpc.NewServer() | |||
testgrpc.RegisterTestServiceServer(s, ss) | |||
ss.S = s |
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: this can be just ss.S = grpc.NewServer() and all the usages can be updated as ss.S.
like ss.S.stop()
etc.
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/gracefulstop_test.go
Outdated
@@ -42,7 +42,9 @@ type delayListener struct { | |||
closeCalled chan struct{} | |||
acceptCalled chan struct{} | |||
allowCloseCh chan struct{} | |||
mu sync.Mutex |
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.
it looks like we are introducing mutex only to update closed
? Then it should be put right above it indicating that anything below is guarded by mutex.
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/gracefulstop_test.go
Outdated
dialed bool | ||
closed bool |
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.
@pvsravani where and how are we using closed
. Why is it needed when switching to stub server?
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.
The closed field ensures the close() method is idempotent. It prevents multiple calls to close() from closing the listener again, which could cause errors.
test/gracefulstop_test.go
Outdated
|
||
// 1. Start Server | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
s.Serve(dlis) | ||
ss.S.Serve(dlis) |
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 should remove this as stubserver.StartTestService
already starts the server
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
@easwars for second review |
test/gracefulstop_test.go
Outdated
@@ -113,31 +113,27 @@ func (s) TestGracefulStop(t *testing.T) { | |||
d := func(ctx context.Context, _ string) (net.Conn, error) { return dlis.Dial(ctx) } |
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.
While you are here, could you please rename this d
as dialer
and move it a line right before it is used. Currently it is only used on line 153, when it is passed to grpc.WithContextDialer
in grpc.DialContext
.
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
} | ||
s := grpc.NewServer() | ||
testgrpc.RegisterTestServiceServer(s, ss) | ||
stubserver.StartTestService(t, ss) |
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 don't think this is doing the correct thing. What we want as part of this test is for GracefulStop
to be called when Accept
is in the middle of accepting a connection.
If you folks have convinced yourself that it actually does what it is supposed to do, then we don't need a sync.WaitGroup
. The same can be accomplished with a done
channel.
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 sync.WaitGroup
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.
yeah i don't think we can use sync.waitgroup
with stubserver.StartService()
. stubserver.StartTestService
creates a server and starts serving in the background. It handles server lifecycle internally. Having a done channel to track gracefulstop will work correctly.
test/gracefulstop_test.go
Outdated
|
||
// 1. Start Server | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
done := make(chan struct{}) |
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.
@pvsravani let's rename this to gracefulStopDone
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/gracefulstop_test.go
Outdated
go func() { | ||
s.Serve(dlis) | ||
wg.Done() | ||
<-dlis.acceptCalled |
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 don't think its needed to move it within go routine. Not that its wrong but this change is not needed i think.
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
} | ||
s := grpc.NewServer() | ||
testgrpc.RegisterTestServiceServer(s, ss) | ||
stubserver.StartTestService(t, ss) |
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.
yeah i don't think we can use sync.waitgroup
with stubserver.StartService()
. stubserver.StartTestService
creates a server and starts serving in the background. It handles server lifecycle internally. Having a done channel to track gracefulstop will work correctly.
@@ -110,36 +109,29 @@ func (s) TestGracefulStop(t *testing.T) { | |||
closeCalled: make(chan struct{}), | |||
allowCloseCh: make(chan struct{}), | |||
} | |||
d := func(ctx context.Context, _ string) (net.Conn, error) { return dlis.Dial(ctx) } |
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: why not just keep this line 113 and remove line 145, 146 and keep line 153? That way we avoid unnecessary diff
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.
Actually Easwar has asked to rename this d as dialer and move it a line right before it is used.
Partially Addresses: #7291
RELEASE NOTES: None