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: Refactor/cleanup xds client tests. #3920

Merged
merged 3 commits into from
Oct 5, 2020

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Oct 2, 2020

  • Cleanup includes the following:
    • Split TestValidateCluster into failure and success cases. I will adding more cases here as part of other PR which adds support to process security configuration at the xdsClient.
    • Use a testutils.Channel to push the fake API client. This allows tests to block on this with a deadline. This addresses a TODO in the code.
    • Add verify*Update functions to test successfully received updates.
    • Push the different updates directly on the xds.Client object instead of going through the fakeAPIClient. This addresses a TODO in the code.
      • Rename variables: c -> client, v2Client -> apiClient, v2ClientCh -> apiClientCh
    • Use short timeouts when blocking for events which are expected to not happen

go test google.golang.org/grpc/xds/internal/client/ now takes ~5s. Used to take ~30s.

#improve-xds-tests

@easwars
Copy link
Contributor Author

easwars commented Oct 2, 2020

@dfawley
I got into this mess when I started writing tests for the other PR that I'm working on (which adds support to process the security configuration received in the Cluster resource), and it wasn't building because I added new fields to the ClusterUpdate struct which made direct struct comparisons no longer possible. I then totally forgot about the initial motivation and sent this as a separate PR (I think it makes sense to send this as a separate PR anyways). But now that PR is blocked on this. So, I'd really appreciate a quicker review on this.
Thanks.

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

I have a couple general comments about context that would apply throughout, but everything else LGTM.

Comment on lines 179 to 180
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
Copy link
Member

Choose a reason for hiding this comment

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

It would be preferable to propagate context instead.

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.

clusterUpdateCh.Send(clusterUpdateErr{u: u, err: err})
})

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout)
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep using the same context throughout the test? Maybe it needs to be higher to avoid flakes, and consequently takes a few seconds longer when there is a failure, but it removes clutter and we aren't trying to enforce specific time bounds on these operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bumped up the defaultTestTimeout to 5s and changed the tests to be using that all the time instead of creating new contexts for every call that needs a context. I couldn't avoid having to create a new one for the calls which are expected to fail though.

@dfawley dfawley assigned easwars and unassigned dfawley Oct 2, 2020
Copy link
Contributor Author

@easwars easwars left a comment

Choose a reason for hiding this comment

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

PTAL. Thanks.

Comment on lines 179 to 180
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
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.

clusterUpdateCh.Send(clusterUpdateErr{u: u, err: err})
})

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
ctx, cancel = context.WithTimeout(context.Background(), 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.

Bumped up the defaultTestTimeout to 5s and changed the tests to be using that all the time instead of creating new contexts for every call that needs a context. I couldn't avoid having to create a new one for the calls which are expected to fail though.

@easwars easwars assigned dfawley and unassigned easwars Oct 2, 2020
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the changes!

ctx, cancel = context.WithTimeout(context.Background(), defaultTestShortTimeout)
defer cancel()
if u, err := clusterUpdateCh.Receive(ctx); err != context.DeadlineExceeded {
sCtx, sCancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
Copy link
Member

Choose a reason for hiding this comment

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

FWIW these could also derive from ctx so they persist the overall test timeout. But since this is so short it doesn't actually matter.

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.

@easwars easwars merged commit dad518a into grpc:master Oct 5, 2020
@easwars easwars deleted the xds_test_refactor branch October 5, 2020 17:12
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2021
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