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
clusterresolver: merge P(p)arseConfig functions #5462
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ import ( | |
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"google.golang.org/grpc/internal/balancer/stub" | ||
"google.golang.org/grpc/balancer" | ||
internalserviceconfig "google.golang.org/grpc/internal/serviceconfig" | ||
"google.golang.org/grpc/xds/internal/balancer/ringhash" | ||
"google.golang.org/grpc/xds/internal/xdsclient/bootstrap" | ||
|
@@ -91,14 +91,6 @@ func TestDiscoveryMechanismTypeUnmarshalJSON(t *testing.T) { | |
} | ||
} | ||
|
||
func init() { | ||
// This is needed now for the config parsing tests to pass. Otherwise they | ||
// will fail with "RING_HASH unsupported". | ||
// | ||
// TODO: delete this once ring-hash policy is implemented and imported. | ||
stub.Register(rhName, stub.BalancerFuncs{}) | ||
} | ||
|
||
const ( | ||
testJSONConfig1 = `{ | ||
"discoveryMechanisms": [{ | ||
|
@@ -257,7 +249,7 @@ func TestParseConfig(t *testing.T) { | |
}, | ||
XDSLBPolicy: &internalserviceconfig.BalancerConfig{ | ||
Name: ringhash.Name, | ||
Config: nil, | ||
Config: &ringhash.LBConfig{MinRingSize: 1024, MaxRingSize: 8388608}, // Ringhash LB config with default min and max. | ||
}, | ||
}, | ||
wantErr: false, | ||
|
@@ -269,11 +261,22 @@ func TestParseConfig(t *testing.T) { | |
}, | ||
} | ||
for _, tt := range tests { | ||
b := balancer.Get(Name) | ||
if b == nil { | ||
t.Fatalf("LB policy %q not registered", Name) | ||
} | ||
cfgParser, ok := b.(balancer.ConfigParser) | ||
if !ok { | ||
t.Fatalf("LB policy %q does not support config parsing", Name) | ||
} | ||
Comment on lines
+264
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of this instead, parser := bb{};..... parser.ParseConfig() rather than this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we do such things at a lot of places. But I feel that even though my version is a little more verbose, it is using the exported API, rather than relying on internals. More often that not, I feel that in tests, this approach serves better in the long run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. Doug left me that suggestion on my Outlier Detection PR mainly because I hadn't coded balancer implementation yet. |
||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := parseConfig([]byte(tt.js)) | ||
got, err := cfgParser.ParseConfig([]byte(tt.js)) | ||
if (err != nil) != tt.wantErr { | ||
t.Fatalf("parseConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
if tt.wantErr { | ||
return | ||
} | ||
if diff := cmp.Diff(got, tt.want); diff != "" { | ||
t.Errorf("parseConfig() got unexpected output, diff (-got +want): %v", diff) | ||
} | ||
|
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.
Personally, I don't mind the alias since it saves verbosity, but I'm indifferent.
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.
ringhash.Name
is not very long compared torhName
but it is way more descriptive.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.
Fair enough.