client: consider service config invalid if loadBalancingConfig… (#3034)

This commit is contained in:
Doug Fawley 2019-09-20 16:07:23 -07:00 committed by GitHub
parent a5e64ec425
commit 6b46f470d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -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 {

View File

@ -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{
{