MCPcopy
hub / github.com/grpc/grpc-go / TestAddressList_SeekTo

Method TestAddressList_SeekTo

balancer/pickfirst/pickfirst_test.go:202–273  ·  view source on GitHub ↗

TestAddressList_SeekTo verifies the behaviour of addressList.seekTo.

(t *testing.T)

Source from the content-addressed store, hash-verified

200
201// TestAddressList_SeekTo verifies the behaviour of addressList.seekTo.
202func (s) TestAddressList_SeekTo(t *testing.T) {
203 addrs := []resolver.Address{
204 {
205 Addr: "192.168.1.1",
206 ServerName: "test-host-1",
207 Attributes: attributes.New("key-1", "val-1"),
208 BalancerAttributes: attributes.New("bal-key-1", "bal-val-1"),
209 },
210 {
211 Addr: "192.168.1.2",
212 ServerName: "test-host-2",
213 Attributes: attributes.New("key-2", "val-2"),
214 BalancerAttributes: attributes.New("bal-key-2", "bal-val-2"),
215 },
216 {
217 Addr: "192.168.1.3",
218 ServerName: "test-host-3",
219 Attributes: attributes.New("key-3", "val-3"),
220 BalancerAttributes: attributes.New("bal-key-3", "bal-val-3"),
221 },
222 }
223
224 addressList := addressList{}
225 addressList.updateAddrs(addrs)
226
227 // Try finding an address in the list.
228 key := resolver.Address{
229 Addr: "192.168.1.2",
230 ServerName: "test-host-2",
231 Attributes: attributes.New("key-2", "val-2"),
232 BalancerAttributes: attributes.New("ignored", "bal-val-2"),
233 }
234
235 if got, want := addressList.seekTo(key), true; got != want {
236 t.Errorf("addressList.seekTo(%v) = %t, want %t", key, got, want)
237 }
238
239 // It should be possible to increment once more now that the pointer has advanced.
240 if got, want := addressList.increment(), true; got != want {
241 t.Errorf("addressList.increment() = %t, want %t", got, want)
242 }
243
244 if got, want := addressList.increment(), false; got != want {
245 t.Errorf("addressList.increment() = %t, want %t", got, want)
246 }
247
248 // Seek to the key again, it is behind the pointer now.
249 if got, want := addressList.seekTo(key), true; got != want {
250 t.Errorf("addressList.seekTo(%v) = %t, want %t", key, got, want)
251 }
252
253 // Seek to a key not in the list.
254 key = resolver.Address{
255 Addr: "192.168.1.5",
256 ServerName: "test-host-5",
257 Attributes: attributes.New("key-5", "val-5"),
258 BalancerAttributes: attributes.New("ignored", "bal-val-5"),
259 }

Callers

nothing calls this directly

Calls 5

updateAddrsMethod · 0.95
seekToMethod · 0.95
incrementMethod · 0.95
NewFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected