Skip to content

Conversation

@eshitachandwani
Copy link
Member

Since the proxy resolver is now initialized in a goroutine triggered by the target resolver's update, we need to ensure that it is fully constructed before allowing it to send updates in tests. This mirrors the real-world behavior, where the proxy resolver cannot send updates unless it has been built. In tests, if we don't wait for this initialization, it may lead to a panic.

RELEASE NOTES: N/A

@eshitachandwani eshitachandwani added this to the 1.73 Release milestone May 8, 2025
@eshitachandwani eshitachandwani added Type: Bug Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. labels May 8, 2025
@codecov
Copy link

codecov bot commented May 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.24%. Comparing base (d00f4ac) to head (72fe781).
Report is 7 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@ ## master #8304 +/- ## ========================================== + Coverage 82.22% 82.24% +0.01%  ========================================== Files 419 419 Lines 41954 41988 +34 ========================================== + Hits 34497 34531 +34  + Misses 5995 5993 -2  - Partials 1462 1464 +2 

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.
Comment on lines 185 to 188
proxyResolverBuilt := make(chan struct{})
proxyResolver.BuildCallback = func(resolver.Target, resolver.ClientConn, resolver.BuildOptions) {
close(proxyResolverBuilt)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make more sense to set up this BuildCallback in the setupDNS function and have it return two values: (*manual.Resolver, chan struct{}). And then we can have the test wait on the second return value the same way you are currently doing in lines 208-215 in this test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 208 to 215
// Wait for the proxy resolver to be built before calling UpdateState.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
select {
case <-proxyResolverBuilt:
case <-ctx.Done():
t.Fatalf("Context timed out waiting for proxy resolver to be built.")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Another possible refactoring would be make this a function for this code block which is repeated in a lot of tests. Something like func mustBuildResolverBuild(ctx context.Context, t *testing.T, buildCh chan struct{}) { ... }.

See: go/go-style/decisions#must-functions

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@easwars easwars assigned eshitachandwani and unassigned easwars and arjan-bal May 8, 2025
@eshitachandwani eshitachandwani requested a review from easwars May 12, 2025 15:34
@eshitachandwani eshitachandwani merged commit ee7f0b6 into grpc:master May 12, 2025
23 of 25 checks passed
eshitachandwani added a commit to eshitachandwani/grpc-go that referenced this pull request May 13, 2025
eshitachandwani added a commit to eshitachandwani/grpc-go that referenced this pull request May 13, 2025
eshitachandwani added a commit that referenced this pull request May 13, 2025
* resolver/delegatingresolver: wait for proxy resolver to be built in test (#8302) * resolver/delegatingresolver: wait for proxy resolver build before update in tests (#8304)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. Type: Bug

3 participants