- Notifications
You must be signed in to change notification settings - Fork 4.6k
resolver/delegatingresolver: wait for proxy resolver build before update in tests #8304
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 ReportAll modified and coverable lines are covered by tests ✅
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 🚀 New features to boost your workflow:
|
| proxyResolverBuilt := make(chan struct{}) | ||
| proxyResolver.BuildCallback = func(resolver.Target, resolver.ClientConn, resolver.BuildOptions) { | ||
| close(proxyResolverBuilt) | ||
| } |
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.
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.
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.
| // 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.") | ||
| } |
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.
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
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.
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