-
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8375 +/- ##
==========================================
- Coverage 82.48% 81.82% -0.67%
==========================================
Files 414 413 -1
Lines 40464 40518 +54
==========================================
- Hits 33376 33152 -224
- Misses 5736 5990 +254
- Partials 1352 1376 +24 🚀 New features to boost your workflow:
|
|
||
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.
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.
@@ -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. |
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. Adding @easwars as a second reviewer.
@@ -484,6 +484,67 @@ func (s) TestBalancerGroupBuildOptions(t *testing.T) { | |||
} | |||
} | |||
|
|||
func (s) TestBalancerGroup_UpdateClientConnState_AfterClose(t *testing.T) { | |||
balancerName := t.Name() | |||
exitIdleCh := make(chan struct{}, 1) |
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 is not a channel used to indicate that ExitIdle
was called. Can you please rename it appropriately. Thanks.
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 changed it to clientConnStateCh
|
||
func (s) TestBalancerGroup_ResolverError_AfterClose(t *testing.T) { | ||
balancerName := t.Name() | ||
exitIdleCh := make(chan struct{}, 1) |
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.
Same here.
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 name as resolveErrorCh
bg.Add(testBalancerIDs[0], balancer.Get(balancerName)) | ||
bg.ExitIdleOne("non-existent-id") | ||
|
||
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.
Please use a channel as used in the other tests instead of a local variable.
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.
chaged to declare channel as exitIdleCh
} | ||
|
||
func (s) TestBalancerGroup_ExitIdleOne_NonExistentID(t *testing.T) { | ||
balancerName := "stub-balancer-test-exit-idle-one-missing-id" |
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 could be t.Name()
as well, right? Any reason for that not to be the case?
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 missed to fixed it,
just updated as t.Name() here too
balancerOne := "stub-balancer-test-balancer-group-exit-idle-one" | ||
balancerTwo := "stub-balancer-test-balancer-group-exit-idle-two" | ||
balancerThree := "stub-balancer-test-balancer-group-exit-idle-three" |
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.
Does three balancers add any more value than two?
And why not?
balancer1 := t.Name() + "-1"
balancer2 := t.Name() + "-2"
balancerNames := []string{balancerOne, balancerTwo, balancerThree} | ||
testIDs := []string{testBalancerIDs[0], testBalancerIDs[1], testBalancerIDs[2]} | ||
|
||
exitIdleCh := make(chan string, len(balancerNames)) | ||
|
||
for _, name := range balancerNames { | ||
stub.Register(name, stub.BalancerFuncs{ | ||
ExitIdle: func(_ *stub.BalancerData) { | ||
exitIdleCh <- name | ||
}, | ||
}) | ||
} |
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 would get rid of the slices and the loops and instead keep this downright simple and dump.
// Have two test IDs: testID1 and testID2
// Have two channels, exitIdleCh1 and exitIdleCh2
// Register two stub balancers, the first one for balancer1 that writes to exitIdleCh1 and the second one for balancer2 that writes to exitIdleCh2
// Create the balancer group, and add the child balancers in there
// Call ExitIdle
// Validate that both exitIdleCh1 and exitIdleCh2 are written to. (I don't think it's an issue if one of those are written to more than once). In this case though, you might have to spawn goroutines to validate that both channels are written to, since we cannot guarantee the order in which they would be written to.
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.
applied in 9d703f2
} | ||
|
||
func (s) TestBalancerGroup_ExitIdle_AfterClose(t *testing.T) { | ||
balancerName := "stub-balancer-test-balancer-group-exit-idle-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.
t.Name
here as well.
|
||
stub.Register(balancerName, stub.BalancerFuncs{ | ||
ExitIdle: func(_ *stub.BalancerData) { | ||
close(exitIdleCh) |
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.
In some places, you write an empty struct to the channel, while in other places, you close the channel. I understand this is minor and super nit-picky, but can you please choose one approach and stay consistent across the PR. Thanks.
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 decided to send an empty struct to a buffered channel, it's more robust and consistent approach 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.
LGTM, modulo the last minor comment.
|
||
func (s) TestBalancerGroup_ExitIdle_AfterClose(t *testing.T) { | ||
balancerName := t.Name() | ||
exitIdleCh := 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.
Oops. Sorry, didn't catch this earlier. This channel needs to have a buffer of 1
. Otherwise, the writer would block if there is no reader.
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.
Thank you, @hugehoo, for your contribution! |
case <-time.After(defaultTestShortTimeout): | ||
} | ||
} | ||
|
||
func (s) TestBalancerExitIdleOne(t *testing.T) { | ||
const balancerName = "stub-balancer-test-balancergroup-exit-idle-one" |
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.
@easwars i just got nitpicking question.
in this pr, i got reviewed to use t.Name()
for balancerName. but some of the cases are still using hard-coded name. Is there any specific reason for it? or would it be better to be updated as t.name()
too?
Fixes: #8118
RELEASE NOTES: N/A