Skip to content

Commit

Permalink
client: consider service config invalid if loadBalancingConfig… (#3034)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Sep 20, 2019
1 parent a5e64ec commit 6b46f47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ func parseServiceConfig(js string) (*ServiceConfig, error) {
}
break
}
if sc.lbConfig == nil {
// We had a loadBalancingConfig field but did not encounter a
// supported policy. The config is considered invalid in this
// case.
err := fmt.Errorf("invalid loadBalancingConfig: no supported policies found")
grpclog.Warningf(err.Error())
return nil, err
}
}

if rsc.MethodConfig == nil {
Expand Down
17 changes: 17 additions & 0 deletions service_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ func (s) TestParseLBConfig(t *testing.T) {
runParseTests(t, testcases)
}

func (s) TestParseNoLBConfigSupported(t *testing.T) {
// We have a loadBalancingConfig field but will not encounter a supported
// policy. The config will be considered invalid in this case.
testcases := []parseTestCase{
{
scjs: `{
"loadBalancingConfig": [{"not_a_balancer1": {} }, {"not_a_balancer2": {}}]
}`,
wantErr: true,
}, {
scjs: `{"loadBalancingConfig": []}`,
wantErr: true,
},
}
runParseTests(t, testcases)
}

func (s) TestParseLoadBalancer(t *testing.T) {
testcases := []parseTestCase{
{
Expand Down

0 comments on commit 6b46f47

Please sign in to comment.