-
Notifications
You must be signed in to change notification settings - Fork 4.5k
xds: Refactor/cleanup xds client tests. #3920
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
@dfawley |
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.
I have a couple general comments about context that would apply throughout, but everything else LGTM.
xds/internal/client/client_test.go
Outdated
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
defer cancel() |
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.
It would be preferable to propagate context instead.
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.
clusterUpdateCh.Send(clusterUpdateErr{u: u, err: err}) | ||
}) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout) |
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.
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.
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.
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.
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.
PTAL. Thanks.
xds/internal/client/client_test.go
Outdated
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
defer cancel() |
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.
clusterUpdateCh.Send(clusterUpdateErr{u: u, err: err}) | ||
}) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout) |
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.
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.
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.
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) |
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.
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.
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.
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 thexdsClient
.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.verify*Update
functions to test successfully received updates.xds.Client
object instead of going through thefakeAPIClient
. This addresses a TODO in the code.c
->client
,v2Client
->apiClient
,v2ClientCh
->apiClientCh
go test google.golang.org/grpc/xds/internal/client/
now takes~5s
. Used to take~30s
.#improve-xds-tests