(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func TestBaseBalancerReserveAttributes(t *testing.T) { |
| 72 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 73 | defer cancel() |
| 74 | validated := make(chan struct{}, 1) |
| 75 | v := func(info PickerBuildInfo) { |
| 76 | defer func() { validated <- struct{}{} }() |
| 77 | for _, sc := range info.ReadySCs { |
| 78 | if sc.Address.Addr == "1.1.1.1" { |
| 79 | if sc.Address.Attributes == nil { |
| 80 | t.Errorf("in picker.validate, got address %+v with nil attributes, want not nil", sc.Address) |
| 81 | } |
| 82 | foo, ok := sc.Address.Attributes.Value("foo").(string) |
| 83 | if !ok || foo != "2233niang" { |
| 84 | t.Errorf("in picker.validate, got address[1.1.1.1] with invalid attributes value %v, want 2233niang", sc.Address.Attributes.Value("foo")) |
| 85 | } |
| 86 | } else if sc.Address.Addr == "2.2.2.2" { |
| 87 | if sc.Address.Attributes != nil { |
| 88 | t.Error("in b.subConns, got address[2.2.2.2] with not nil attributes, want nil") |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | pickBuilder := &testPickBuilder{validate: v} |
| 94 | b := (&baseBuilder{pickerBuilder: pickBuilder}).Build(&testClientConn{ |
| 95 | newSubConn: func(_ []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) { |
| 96 | return &testSubConn{updateState: opts.StateListener}, nil |
| 97 | }, |
| 98 | }, balancer.BuildOptions{}).(*baseBalancer) |
| 99 | |
| 100 | b.UpdateClientConnState(balancer.ClientConnState{ |
| 101 | ResolverState: resolver.State{ |
| 102 | Addresses: []resolver.Address{ |
| 103 | {Addr: "1.1.1.1", Attributes: attributes.New("foo", "2233niang")}, |
| 104 | {Addr: "2.2.2.2", Attributes: nil}, |
| 105 | }, |
| 106 | }, |
| 107 | }) |
| 108 | select { |
| 109 | case <-validated: |
| 110 | case <-ctx.Done(): |
| 111 | t.Fatalf("timed out waiting for UpdateClientConnState to call picker.Build") |
| 112 | } |
| 113 | |
| 114 | for sc := range b.scStates { |
| 115 | sc.(*testSubConn).updateState(balancer.SubConnState{ConnectivityState: connectivity.Ready, ConnectionError: nil}) |
| 116 | select { |
| 117 | case <-validated: |
| 118 | case <-ctx.Done(): |
| 119 | t.Fatalf("timed out waiting for UpdateClientConnState to call picker.Build") |
| 120 | } |
| 121 | } |
| 122 | } |
nothing calls this directly
no test coverage detected