Skip to content

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

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

Conversation

hugehoo
Copy link
Contributor

@hugehoo hugehoo commented May 31, 2025

Fixes: #8118

  • Add test cases for
    • ExitIdle()
    • ExitIdleOne()
    • UpdateClientConnState
    • ResolverError

RELEASE NOTES: N/A

Copy link

codecov bot commented May 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.42%. Comparing base (a5e7cd6) to head (c33ece3).

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     

see 24 files with indirect coverage changes

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

@eshitachandwani eshitachandwani self-requested a review June 6, 2025 13:52
@eshitachandwani eshitachandwani self-assigned this Jun 6, 2025
bg.Close()
bg.ExitIdleOne(testBalancerIDs[0])

if called {
Copy link
Member

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):
	}
    ```

Copy link
Member

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) {
Copy link
Member

@eshitachandwani eshitachandwani Jun 6, 2025

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.

Comment on lines 796 to 800
for _, expected := range balancerNames {
if !called[expected] {
t.Errorf("ExitIdle was not called for sub-balancer registered as %q", expected)
}
}
Copy link
Member

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.

Copy link
Contributor Author

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
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
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.

@hugehoo hugehoo requested a review from eshitachandwani June 8, 2025 08:37

stub.Register(balancerName, stub.BalancerFuncs{
UpdateClientConnState: func(_ *stub.BalancerData, _ balancer.ClientConnState) error {
called = true
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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):
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
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):
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
case <-time.After(time.Second):
case <-time.After(defaultTestTImeout):

Copy link
Contributor Author

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"
Copy link
Contributor

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.

@hugehoo hugehoo force-pushed the test-coverage-ExitIdle branch from 9a6e323 to f2b8e02 Compare June 15, 2025 14:14
@eshitachandwani
Copy link
Member

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.

@hugehoo
Copy link
Contributor Author

hugehoo commented Jun 20, 2025

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.

@eshitachandwani
Copy link
Member

Hey @hugehoo are you still working on this PR?

@eshitachandwani eshitachandwani added Type: Testing Area: Testing Includes tests and testing utilities that we have for unit and e2e tests within our repo. labels Jul 14, 2025
@eshitachandwani eshitachandwani added this to the 1.75 Release milestone Jul 14, 2025
Copy link

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.

@github-actions github-actions bot added the stale label Jul 20, 2025
@hugehoo hugehoo requested a review from eshitachandwani July 20, 2025 08:40
@hugehoo
Copy link
Contributor Author

hugehoo commented Jul 20, 2025

Hey @hugehoo are you still working on this PR?

sorry for late, i requested for review now

@github-actions github-actions bot removed the stale label Jul 20, 2025
@hugehoo hugehoo requested a review from easwars July 20, 2025 13:21
@eshitachandwani
Copy link
Member

Hey @hugehoo ,
The name of this test was recently changed : tests (tests, 1.24, arm64, ubuntu-24.04-arm) , and that is why the test is stuck. Can you merge master so that the test can run again?

@eshitachandwani eshitachandwani self-assigned this Jul 22, 2025
@hugehoo
Copy link
Contributor Author

hugehoo commented Jul 22, 2025

Hey @hugehoo , The name of this test was recently changed : tests (tests, 1.24, arm64, ubuntu-24.04-arm) , and that is why the test is stuck. Can you merge master so that the test can run again?

@eshitachandwani thx for the info, i just merged it and run the test again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Testing Includes tests and testing utilities that we have for unit and e2e tests within our repo. Status: Requires Reporter Clarification Type: Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

balancergroup: Add test coverage
3 participants