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

internal/testutils: add a new test type that implements resolver.ClientConn #6668

Merged
merged 11 commits into from
Oct 12, 2023

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Sep 29, 2023

Summary of changes:

  • internal/testutils:
    • Add a new ResolverClientConn type that implements the resolver.ClientConn interface
    • Rename the existing testutils.TestClientConn to testutils.BalancerClientConn and update all references from existing tests
  • internal/resolver/dns:
    • Add a new internal/resolver/dns/internal package to house functionality shared between the dns package and its tests
    • Move the fake implementation of the net.Resolver interface used from tests into a separate file. This can do with some cleanup to make it more readable and understandable.
    • Move the DNS resolver tests to the dns_test package
    • Cleanup the existing DNS resolver tests:
      • Use t.Run wherever possible
      • Use the grpctest.Tester and get rid of direct calls to the leakchecker
      • Get rid of TestMain
      • Introduce helper functions for commonly used functionality

In a follow-up PR, I will using the testutils.ResolverClientConn type from the xDS resolver tests.

#resource-agnostic-xdsclient-api

RELEASE NOTES: none

@easwars easwars requested a review from dfawley September 29, 2023 15:34
@easwars easwars added this to the 1.59 Release milestone Sep 29, 2023
internal/testutils/resolver.go Outdated Show resolved Hide resolved
internal/testutils/resolver.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned easwars and unassigned dfawley Oct 5, 2023
@easwars easwars assigned dfawley and unassigned easwars Oct 5, 2023
@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

❗ No coverage uploaded for pull request base (master@fd9ef72). Click here to learn what that means.
The diff coverage is n/a.

Additional details and impacted files

@ginayeh ginayeh modified the milestones: 1.59 Release, 1.60 Release Oct 5, 2023
Comment on lines 46 to 52
func NewResolverClientConn(t *testing.T, updateState func(resolver.State) error, reportError func(error)) *ResolverClientConn {
return &ResolverClientConn{
logger: t,
updateStateF: updateState,
reportErrorF: reportError,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we just delete this constructor and export the fields? I think it would be a little more ergonomic since the fields would be initialized by name instead of position in the parameter list.

E.g.

rcc := &testutils.ResolverClientConn{
	T: t,
	UpdateStateF: func(...) {},
	ReportErrorF: func(...) {},
}

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 was initially hesitant to do that because I didn't want to store a testing.T in this type. Ended up exporting the logger interface.

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.

// ResolverClientConn is a fake implemetation of the resolver.ClientConn
// interface to be used in tests.
type ResolverClientConn struct {
resolver.ClientConn // Embedding the interface to avoid implementing deprecated methods.
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 add something to remind ourselves to remove this in the future?

var _ = ResolverClientConn{}.SomeDeprecatedThing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm ... I don't understand this 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.

Writing something like var _ = ResolverClientConn{}.NewAddress results in an init time panic since this method is not implemented in ResolverClientConn. I initially made a commit which had this and failed to realize that it was causing a panic. So, I had to undo this in the latest commit.

target: ":80",
},
{
name: "",
Copy link
Member

Choose a reason for hiding this comment

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

Add a name?

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 honestly don't know what this case is testing. Do you?

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 56 to 65
tbl: map[string][]string{
"foo.bar.com": {"1.2.3.4", "5.6.7.8"},
"ipv4.single.fake": {"1.2.3.4"},
"srv.ipv4.single.fake": {"2.4.6.8"},
"srv.ipv4.multi.fake": {},
"srv.ipv6.single.fake": {},
"srv.ipv6.multi.fake": {},
"ipv4.multi.fake": {"1.2.3.4", "5.6.7.8", "9.10.11.12"},
"ipv6.single.fake": {"2607:f8b0:400a:801::1001"},
"ipv6.multi.fake": {"2607:f8b0:400a:801::1001", "2607:f8b0:400a:801::1002", "2607:f8b0:400a:801::1003"},
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I was hoping this and the below table would go away in any rewrite. Is there any way to make this declared in a constructor instead? If it's too much work we can punt, but IMO splitting test code that depends on each other into very distant places is a very bad practice.

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 will look into this. But if we can do that as part of a follow up PR, that would be good, since many of the other xDS PRs are gated on the change to add testutils.ResolverClientConn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved the host lookup and srv lookup parts. Working on improving the txt lookup.

// resolver functionality, with scfs as the input and scs used for validation of
// the output. For scfs[3], it corresponds to empty service config, since there
// isn't a matched choice.
var scfs = []string{
Copy link
Member

Choose a reason for hiding this comment

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

Similar - these are very magical and nowhere near the code that relies on them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here. Thanks.

@dfawley dfawley assigned easwars and unassigned dfawley Oct 10, 2023
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.

Approved for the current set of changes modulo:

  • Delete test case named ""
  • Add var _ business so we know when to un-embed

@easwars
Copy link
Contributor Author

easwars commented Oct 12, 2023

Approved for the current set of changes modulo:

  • Delete test case named ""

Done.

  • Add var _ business so we know when to un-embed

Couldn't add this. The comment thread around this has more details.

@arvindbr8 arvindbr8 assigned arvindbr8 and easwars and unassigned easwars and arvindbr8 Oct 12, 2023
@easwars easwars merged commit dd4c0ad into grpc:master Oct 12, 2023
13 checks passed
@easwars easwars deleted the test_resolver_clientconn branch October 12, 2023 17:09
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.

4 participants