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

xdsclient: improve CDS watchers test #5693

Merged
merged 4 commits into from
Oct 18, 2022
Merged

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Oct 6, 2022

Improve the CDS watchers test by moving to an e2e style test which verifies functionality without relying on any internal state.

This PR is similar to how the LDS watchers test was cleaned up in #5506.

#resource-agnostic-xdsclient-api

RELEASE NOTES: n/a

@easwars easwars requested a review from zasweq October 6, 2022 17:22
@easwars easwars added this to the 1.51 Release milestone Oct 6, 2022
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.

Phew done with PRs I think. Some minor comments on this one.

xds/internal/xdsclient/client_new.go Outdated Show resolved Hide resolved
Comment on lines 47 to 48
// config_source specifier for the `lrs_server` field which is not set to
// `self`, and hence is expected to be NACKed by the client.
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 lrs_server field isn't the thing being set to self. ConfigSourceSpecifier in the lrs_server field is not set to self.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't that what the comment says?

contains a config_source specifier for the `lrs_server` field which is not set to `self`

Copy link
Contributor

@zasweq zasweq Oct 18, 2022

Choose a reason for hiding this comment

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

config_source specifier this should have underscore in between source and specifier. Also, add "which" before "contains" earlier in this comment.

if err := mgmtServer.Update(ctx, resources); err != nil {
t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err)
}
if err := verifyNoClusterUpdate(ctx, updateCh); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're not wrapping the error from this, rather than just saying unexpected update, can you explicitly state in the returned error (or wrap it) stating that we don't expect any update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't an unexpected update mean that you received an update when you did not expect one?

Copy link
Contributor

Choose a reason for hiding this comment

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

To me, unexpected update also encompasses the case where you receive a bad update with fields not as expected. I feel like I've written many a if diff := cmp.Diff; diff != "" {t.Fatalf("Unexpected update (-got, +want) %v", diff} or whatever the exact syntax is. I feel strongly about this :D.

xds/internal/xdsclient/e2e_test/cds_watchers_test.go Outdated Show resolved Hide resolved
xds/internal/xdsclient/e2e_test/cds_watchers_test.go Outdated Show resolved Hide resolved
xds/internal/xdsclient/e2e_test/cds_watchers_test.go Outdated Show resolved Hide resolved
}
if err := verifyNoClusterUpdate(ctx, updateCh1); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as previously, please switch the returned error to explicitly state expecting no cluster update. This keeps it consistent to the got/want/diffs we all know and love.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As stated in the previous comment about the same thing, unexpected update means the same as unexpected update when we don't want one. We use this pattern quite a lot in our tests. Like we don't have a want section here. We have received something when we dont expect to receive anything. So, I feel this is good enough. Let me know if you feel strongly about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Commented on other one.

xds/internal/xdsclient/e2e_test/cds_watchers_test.go Outdated Show resolved Hide resolved
xds/internal/xdsclient/e2e_test/cds_watchers_test.go Outdated Show resolved Hide resolved
xds/internal/xdsclient/e2e_test/cds_watchers_test.go Outdated Show resolved Hide resolved
@zasweq zasweq assigned easwars and unassigned zasweq Oct 14, 2022
@easwars easwars assigned zasweq and unassigned easwars Oct 17, 2022
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 outside my replies.

Comment on lines 47 to 48
// config_source specifier for the `lrs_server` field which is not set to
// `self`, and hence is expected to be NACKed by the client.
Copy link
Contributor

@zasweq zasweq Oct 18, 2022

Choose a reason for hiding this comment

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

config_source specifier this should have underscore in between source and specifier. Also, add "which" before "contains" earlier in this comment.

if err := mgmtServer.Update(ctx, resources); err != nil {
t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err)
}
if err := verifyNoClusterUpdate(ctx, updateCh); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

To me, unexpected update also encompasses the case where you receive a bad update with fields not as expected. I feel like I've written many a if diff := cmp.Diff; diff != "" {t.Fatalf("Unexpected update (-got, +want) %v", diff} or whatever the exact syntax is. I feel strongly about this :D.

// update from the management server containing both resources results in the
// invocation of all watch callbacks.
//
// The test is run with both old and new style names.
Copy link
Contributor

@zasweq zasweq Oct 18, 2022

Choose a reason for hiding this comment

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

I'm suggesting changing docstring specifying you use old and new in same resource, rather than a different test. Just to keep explanations consistent with docstrings earlier explaining you have seperate tests for old and new style resources. Here and the other place I commented about this explicit stating of how it uses old and new style names.

Comment on lines 635 to 645
// TestCDSWatch_ResourceRemoved covers the cases where a resource being watched
// is removed from the management server. The test verifies the following
// scenarios:
// 1. Removing a resource should trigger the watch callback with a resource
// removed error. It should not trigger the watch callback for an unrelated
// resource.
// 2. An update to another resource should result in the invocation of the watch
// callback associated with that resource. It should not result in the
// invocation of the watch callback associated with the deleted resource.
//
// The test is run with both old and new style names.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as others, I'm suggesting changing docstring specifying you use old and new in same resource, rather than a different test. Just to keep explanations consistent with docstrings earlier.

}
if err := verifyNoClusterUpdate(ctx, updateCh1); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented on other one.

// update from the management server containing both resources results in the
// invocation of all watch callbacks.
//
// The test is run with both old and new style names.
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh whoops lol on wrong partition I was thinking about.

@zasweq zasweq assigned easwars and unassigned zasweq Oct 18, 2022
@easwars easwars merged commit dbb8e2b into grpc:master Oct 18, 2022
@easwars easwars deleted the cds_watchers_test branch October 18, 2022 19:20
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2023
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.

2 participants