(t *testing.T)
| 136 | } |
| 137 | |
| 138 | func (s) TestOneEndpoint(t *testing.T) { |
| 139 | wantAddr1 := resolver.Address{Addr: testBackendAddrStrs[0]} |
| 140 | cc, _, p0 := setupTest(t, []resolver.Endpoint{{Addresses: []resolver.Address{wantAddr1}}}) |
| 141 | ring0 := p0.(*picker).ring |
| 142 | |
| 143 | firstHash := ring0.items[0].hash |
| 144 | // firstHash-1 will pick the first (and only) SubConn from the ring. |
| 145 | testHash := firstHash - 1 |
| 146 | // The first pick should be queued, and should trigger a connection to the |
| 147 | // only Endpoint which has a single address. |
| 148 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 149 | defer cancel() |
| 150 | if _, err := p0.Pick(balancer.PickInfo{Ctx: iringhash.SetXDSRequestHash(ctx, testHash)}); err != balancer.ErrNoSubConnAvailable { |
| 151 | t.Fatalf("first pick returned err %v, want %v", err, balancer.ErrNoSubConnAvailable) |
| 152 | } |
| 153 | var sc0 *testutils.TestSubConn |
| 154 | select { |
| 155 | case <-ctx.Done(): |
| 156 | t.Fatalf("Timed out waiting for SubConn creation.") |
| 157 | case sc0 = <-cc.NewSubConnCh: |
| 158 | } |
| 159 | if got, want := sc0.Addresses[0].Addr, wantAddr1.Addr; got != want { |
| 160 | t.Fatalf("SubConn.Addresses = %v, want = %v", got, want) |
| 161 | } |
| 162 | select { |
| 163 | case <-sc0.ConnectCh: |
| 164 | case <-time.After(defaultTestTimeout): |
| 165 | t.Errorf("timeout waiting for Connect() from SubConn %v", sc0) |
| 166 | } |
| 167 | |
| 168 | // Send state updates to Ready. |
| 169 | sc0.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) |
| 170 | sc0.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) |
| 171 | if err := cc.WaitForConnectivityState(ctx, connectivity.Ready); err != nil { |
| 172 | t.Fatal(err) |
| 173 | } |
| 174 | |
| 175 | // Test pick with one backend. |
| 176 | p1 := <-cc.NewPickerCh |
| 177 | for i := 0; i < 5; i++ { |
| 178 | gotSCSt, _ := p1.Pick(balancer.PickInfo{Ctx: iringhash.SetXDSRequestHash(ctx, testHash)}) |
| 179 | if gotSCSt.SubConn != sc0 { |
| 180 | t.Fatalf("picker.Pick, got %v, want SubConn=%v", gotSCSt, sc0) |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // TestThreeBackendsAffinity covers that there are 3 SubConns, RPCs with the |
| 186 | // same hash always pick the same SubConn. When the one picked is down, another |
nothing calls this directly
no test coverage detected