-
Notifications
You must be signed in to change notification settings - Fork 4.5k
grpctest: add test coverages of ExitIdle
#8375
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
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 #8375 +/- ##
==========================================
- Coverage 82.48% 82.42% -0.06%
==========================================
Files 414 414
Lines 40464 40464
==========================================
- Hits 33376 33354 -22
- Misses 5736 5752 +16
- Partials 1352 1358 +6 🚀 New features to boost your workflow:
|
bg.Close() | ||
bg.ExitIdleOne(testBalancerIDs[0]) | ||
|
||
if called { |
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 should be changed to waiting for a channel similar to the test above and wait for defaultTestShortTimeout
to make sure it that ExitIdleOne
is not called. Something like :
select {
case <-exitIdleCh:
t.Fatalf("ExitIdleOne called on sub-balancer after BalancerGroup was closed")
case <-time.After(defaultTestShortTimeout):
}
```
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 in all other tests.
} | ||
} | ||
|
||
func (s) TestBalancerGroup_ExitIdleOne_NonExistentID(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.
I am not sure how helpful this test is, maybe @arjan-bal or @easwars might be able to judge better.
for _, expected := range balancerNames { | ||
if !called[expected] { | ||
t.Errorf("ExitIdle was not called for sub-balancer registered as %q", expected) | ||
} | ||
} |
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 block makes sense only in the case where one or more of the balancer's ExitIdle
method is called twice and one of the balancer's method is not called. We could combine this check with the above block itself by checking if called[name]
is already true and fail if it is.
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.
@eshitachandwani thx for the review, i updated as combining checks within the select statement.
|
||
stub.Register(balancerName, stub.BalancerFuncs{ | ||
ExitIdle: func(_ *stub.BalancerData) { | ||
called = true |
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.
called = true | |
close(exitIdleCh) |
Here instead of a variable , a channel can be closed and waited for in a select block since this operation is done only once.
|
||
stub.Register(balancerName, stub.BalancerFuncs{ | ||
UpdateClientConnState: func(_ *stub.BalancerData, _ balancer.ClientConnState) error { | ||
called = true |
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.
Change to use channel here too. In the check add a defaultShortTestTimeout
case along with wait for channel in select block.
|
||
stub.Register(balancerName, stub.BalancerFuncs{ | ||
ResolverError: func(_ *stub.BalancerData, _ error) { | ||
called = true |
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.
Change to use channel here too. In the check add a defaultShortTestTimeout
case along with wait for channel in select block.
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.
changed all tests to use channel instead of boolean
select { | ||
case <-exitIdleCh: | ||
t.Fatalf("ExitIdle was called on sub-balancer even after BalancerGroup was closed") | ||
case <-time.After(defaultTestTimeout): |
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.
case <-time.After(defaultTestTimeout): | |
case <-time.After(defaultShortTestTimeout): |
We use defaultShortTestTimeout
to wait for some time for cases that are not expected to happen , and use defaultTestTimeout
for cases that are expected to happen.
bg.ExitIdleOne(testBalancerIDs[0]) | ||
|
||
select { | ||
case <-time.After(time.Second): |
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.
case <-time.After(time.Second): | |
case <-time.After(defaultTestTImeout): |
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.
updated as defaultTestTimeout
but tests got failed. i should try other way
@@ -484,6 +484,63 @@ func (s) TestBalancerGroupBuildOptions(t *testing.T) { | |||
} | |||
} | |||
|
|||
func (s) TestBalancerGroup_UpdateClientConnState_AfterClose(t *testing.T) { | |||
balancerName := "stub-balancer-test-update-client-state-after-close" |
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: balancerName
could be set to t.Name()
. Here and elsewhere.
9a6e323
to
f2b8e02
Compare
Hey @hugehoo , is this ready for review or is it still a work in progress? If it is ready for review , please request a review and unassign yourself so that we can review it. |
hi, i'm still working on this pr, testing is still broken. i think i can request a review within this weekend. |
Hey @hugehoo are you still working on this PR? |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
sorry for late, i requested for review now |
Hey @hugehoo , |
@eshitachandwani thx for the info, i just merged it and run the test again. |
Fixes: #8118
RELEASE NOTES: N/A