Skip to content
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

xds/resolver: move service watching tests to resolver_test package #6682

Merged
merged 3 commits into from
Oct 12, 2023

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Oct 3, 2023

The testutils.ResolverClientConn found in internal/testutils/resolver.go is part of an in-progress PR: #6668. So, you can skip reviewing it here unless we get done here first before the other PR.

Summary of changes:

  • Moves the tests in xds/internal/resolver/watch_service_test.go to resolver_test package, thereby making them not rely on any internal details

  • Also removes the following two tests:

    • TestServiceWatchLDSUpdateMaxStreamDuration: This will already tested in one of the config selector tests, and the same test will be enhanced to also verify the service config pushed to the channel
    • TestServiceNotCancelRDSOnSameLDSUpdate
      • This is not worth testing because the go-control-plane sends both the LDS and RDS resource even when we update only the LDS resource. So, gRPC will anyways end up acking the RDS resource as well.
  • Adds some helper functions (more to come in other PRs) that are used to make tests shorter and will be used in other tests as well

  • Export scheme from the resolver package

  • Add a String() method on the resolver.Target type for better logging output

#resource-agnostic-xdsclient-api

RELEASE NOTES: none

@easwars easwars added this to the 1.59 Release milestone Oct 3, 2023
@easwars easwars requested a review from zasweq October 3, 2023 23:36
@ginayeh ginayeh modified the milestones: 1.59 Release, 1.60 Release Oct 5, 2023
Copy link
Contributor

@zasweq zasweq left a comment

Choose a reason for hiding this comment

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

LGTM module the callback api, which will affect the other one I approved as well for the cluster specifier plugins. Curious to see how it looks after change but it'll be pretty similar feeling I think.

Comment on lines 289 to 293
// String returns a string representation of Target.
func (t Target) String() string {
return t.URL.String()
}

Copy link
Contributor

Choose a reason for hiding this comment

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

These changes collide with the other pr you sent out, just a heads up. This and scheme.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've rebased now and cleanup things a bit. Will merge once GitHub Actions is happy.

)

func (s) TestFindBestMatchingVirtualHost(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a pretty clean and appropriately scoped unit test to delete. This helper function is still needed in the generic client api? Would prefer leaving this, and moving the tests that are e2e to separate package. I feel like some unit tests are appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved these tests to the xdsresource package as part of another PR that you approved and I've already merged it. Actually, if and when I rebase this to master, this diff will disappear.

Comment on lines 87 to 97
// Verifies that no update is pushed on the fake resolver.ClientConn. Calls
// t.Fatal() if an update is received before defaultTestShortTimeout expires.
func verifyNoUpdateFromResolver(ctx context.Context, t *testing.T, tcc *testutils.ResolverClientConn) {
t.Helper()

sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
defer sCancel()
select {
case <-sCtx.Done():
case u := <-tcc.StateCh:
t.Fatalf("Received update from resolver %v when none expected", u)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will need to rework this to callback style API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied over the update I made on the ResolverClientConn to switch it to use callbacks, and I've made changes to the call sites here.

Comment on lines 114 to 126
case <-ctx.Done():
t.Fatalf("Timeout waiting for an update from the resolver: %v", ctx.Err())
case state = <-tcc.StateCh:
if err := state.ServiceConfig.Err; err != nil {
t.Fatalf("Received error in service config: %v", state.ServiceConfig.Err)
}
if wantSC == "" {
break
}
wantSCParsed := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(wantSC)
if !internal.EqualServiceConfigForTesting(state.ServiceConfig.Config, wantSCParsed.Config) {
t.Fatalf("Got service config:\n%s \nWant service config:\n%s", cmp.Diff(nil, state.ServiceConfig.Config), cmp.Diff(nil, wantSCParsed.Config))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here (also part of your other PR)

Copy link
Contributor 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 167 to 170
// - A reference to the xDS management server
// - A reference to the test resolver.ClientConn to verify service config pushed
// on the channel
// - A channel to read requested route configuration resource names from
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the above bullets have periods haha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you really want me to fix that? This is not going to be part of a godoc.

}
t.Cleanup(mgmtServer.Stop)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why t.Cleanup over defer? Just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

t.Cleanup is better in helpers for a number of reasons:

  • the helper does not have to return a cancel func that the callsites have to defer
  • if the helper does things multiple things that can fail, it can be tricky to correctly cleanup when one of those things fail and an appropriate cancel func has to be returned to the caller. With t.Cleanup though, things are very simple. The helper can simply add things to be run at the end of the test and call t.Fatal when something fails.

Also, t.Cleanup gets run at the end of the test and defer runs at the end of the function. So, you really can't defer cleanup things from a helper, because you really want that cleanup to happen at the end of the test and not at the end of the helper.

serviceUpdateCh.Send(serviceUpdateErr{u: update, err: err})
}, nil)
defer cancelWatch()
// Waits for the wantNames to be pushed on to namesCh. Fails the test by calling
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: waitForResourceNames waits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general, it is considered good practice to follow the function level comment style used for exported functions for unexported functions as well. But it makes things easy when you might decide to export it. But here, there is not a very good chance of exporting this. But anyways, changed it.

Comment on lines 264 to 265
// the new resource, and once successfully resolved, sends an update on the
// channel.
Copy link
Contributor

Choose a reason for hiding this comment

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

s "sends an update on the channel" to "verifies receives update from channel" although this is callback based now.

Copy link
Contributor 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 +260 to +39
// Tests the case where the listener resource starts pointing to a new route
// configuration resource after the xDS resolver has successfully resolved the
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention old system (i.e. listener resource was already points to a route configuration, and then gets a new update pointing to a new one). And optionally put test name at beginning of comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mention old system

That information is conveyed by this:
after the xDS resolver has successfully resolved the service name and pushed an update on the channel

And optionally put test name at beginning of comment

I used to do that earlier, but after a comment from Doug, I've switched to this approach of starting the comment with "Tests .....".

// Tests the case where the listener resource changes to contain an inline route
// configuration and changes back to having a route configuration resource name.
// Verifies that the expected xDS resource names are requested by the resolver
// and the update pushed to the channel contains the expected service config.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this comment to callback based API is how verification happens mechanically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworded it.

@zasweq zasweq assigned easwars and unassigned zasweq Oct 6, 2023
@easwars easwars force-pushed the xds_resolver_cleanup_3 branch from 5d56708 to f5c1545 Compare October 12, 2023 19:05
@easwars easwars force-pushed the xds_resolver_cleanup_3 branch from f5c1545 to 4cdc587 Compare October 12, 2023 19:08
@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #6682 (4cdc587) into master (5a6773c) will increase coverage by 0.03%.
The diff coverage is n/a.

Additional details and impacted files

@easwars easwars merged commit c76442c into grpc:master Oct 12, 2023
13 checks passed
@easwars easwars deleted the xds_resolver_cleanup_3 branch October 12, 2023 19:21
arvindbr8 pushed a commit to arvindbr8/grpc-go that referenced this pull request Nov 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants