@@ -33,7 +33,6 @@ import (
3333 "google.golang.org/grpc/credentials/insecure"
3434 "google.golang.org/grpc/internal"
3535 "google.golang.org/grpc/internal/channelz"
36- "google.golang.org/grpc/internal/envconfig"
3736 "google.golang.org/grpc/internal/grpcrand"
3837 "google.golang.org/grpc/internal/stubserver"
3938 "google.golang.org/grpc/internal/testutils"
@@ -376,8 +375,6 @@ func (s) TestPickFirst_StickyTransientFailure(t *testing.T) {
376375
377376// Tests the PF LB policy with shuffling enabled.
378377func (s ) TestPickFirst_ShuffleAddressList (t * testing.T ) {
379- defer func (old bool ) { envconfig .PickFirstLBConfig = old }(envconfig .PickFirstLBConfig )
380- envconfig .PickFirstLBConfig = true
381378 const serviceConfig = `{"loadBalancingConfig": [{"pick_first":{ "shuffleAddressList": true }}]}`
382379
383380 // Install a shuffler that always reverses two entries.
@@ -429,45 +426,6 @@ func (s) TestPickFirst_ShuffleAddressList(t *testing.T) {
429426 }
430427}
431428
432- // Tests the PF LB policy with the environment variable support of address list
433- // shuffling disabled.
434- func (s ) TestPickFirst_ShuffleAddressListDisabled (t * testing.T ) {
435- defer func (old bool ) { envconfig .PickFirstLBConfig = old }(envconfig .PickFirstLBConfig )
436- envconfig .PickFirstLBConfig = false
437- const serviceConfig = `{"loadBalancingConfig": [{"pick_first":{ "shuffleAddressList": true }}]}`
438-
439- // Install a shuffler that always reverses two entries.
440- origShuf := grpcrand .Shuffle
441- defer func () { grpcrand .Shuffle = origShuf }()
442- grpcrand .Shuffle = func (n int , f func (int , int )) {
443- if n != 2 {
444- t .Errorf ("Shuffle called with n=%v; want 2" , n )
445- return
446- }
447- f (0 , 1 ) // reverse the two addresses
448- }
449-
450- // Set up our backends.
451- cc , r , backends := setupPickFirst (t , 2 )
452- addrs := stubBackendsToResolverAddrs (backends )
453-
454- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
455- defer cancel ()
456-
457- // Send a config with shuffling enabled. This will reverse the addresses,
458- // so we should connect to backend 1 if shuffling is supported. However
459- // with it disabled at the start of the test, we will connect to backend 0
460- // instead.
461- shufState := resolver.State {
462- ServiceConfig : parseServiceConfig (t , r , serviceConfig ),
463- Addresses : []resolver.Address {addrs [0 ], addrs [1 ]},
464- }
465- r .UpdateState (shufState )
466- if err := pickfirst .CheckRPCsToBackend (ctx , cc , addrs [0 ]); err != nil {
467- t .Fatal (err )
468- }
469- }
470-
471429// Test config parsing with the env var turned on and off for various scenarios.
472430func (s ) TestPickFirst_ParseConfig_Success (t * testing.T ) {
473431 // Install a shuffler that always reverses two entries.
@@ -483,49 +441,23 @@ func (s) TestPickFirst_ParseConfig_Success(t *testing.T) {
483441
484442 tests := []struct {
485443 name string
486- envVar bool
487444 serviceConfig string
488445 wantFirstAddr bool
489446 }{
490447 {
491- name : "env var disabled with empty pickfirst config" ,
492- envVar : false ,
493- serviceConfig : `{"loadBalancingConfig": [{"pick_first":{}}]}` ,
494- wantFirstAddr : true ,
495- },
496- {
497- name : "env var disabled with non-empty good pickfirst config" ,
498- envVar : false ,
499- serviceConfig : `{"loadBalancingConfig": [{"pick_first":{ "shuffleAddressList": true }}]}` ,
500- wantFirstAddr : true ,
501- },
502- {
503- name : "env var disabled with non-empty bad pickfirst config" ,
504- envVar : false ,
505- serviceConfig : `{"loadBalancingConfig": [{"pick_first":{ "shuffleAddressList": 666 }}]}` ,
506- wantFirstAddr : true ,
507- },
508- {
509- name : "env var enabled with empty pickfirst config" ,
510- envVar : true ,
448+ name : "empty pickfirst config" ,
511449 serviceConfig : `{"loadBalancingConfig": [{"pick_first":{}}]}` ,
512450 wantFirstAddr : true ,
513451 },
514452 {
515- name : "env var enabled with empty good pickfirst config" ,
516- envVar : true ,
453+ name : "empty good pickfirst config" ,
517454 serviceConfig : `{"loadBalancingConfig": [{"pick_first":{ "shuffleAddressList": true }}]}` ,
518455 wantFirstAddr : false ,
519456 },
520457 }
521458
522459 for _ , test := range tests {
523460 t .Run (test .name , func (t * testing.T ) {
524- // Set the env var as specified by the test table.
525- origPickFirstLBConfig := envconfig .PickFirstLBConfig
526- envconfig .PickFirstLBConfig = test .envVar
527- defer func () { envconfig .PickFirstLBConfig = origPickFirstLBConfig }()
528-
529461 // Set up our backends.
530462 cc , r , backends := setupPickFirst (t , 2 )
531463 addrs := stubBackendsToResolverAddrs (backends )
@@ -555,10 +487,6 @@ func (s) TestPickFirst_ParseConfig_Success(t *testing.T) {
555487
556488// Test config parsing for a bad service config.
557489func (s ) TestPickFirst_ParseConfig_Failure (t * testing.T ) {
558- origPickFirstLBConfig := envconfig .PickFirstLBConfig
559- envconfig .PickFirstLBConfig = true
560- defer func () { envconfig .PickFirstLBConfig = origPickFirstLBConfig }()
561-
562490 // Service config should fail with the below config. Name resolvers are
563491 // expected to perform this parsing before they push the parsed service
564492 // config to the channel.
0 commit comments