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

Method TestEndpointUpdate

interop/orcalb_test.go:283–348  ·  view source on GitHub ↗

TestEndpointUpdate verifies client behavior in response to a resolver update that changes an endpoint's address. It ensures that the client disconnects from the old address and connects to the new address via pick_first. It also validates that the OOB listener for the old connection is stopped, and

(t *testing.T)

Source from the content-addressed store, hash-verified

281// and a new OOB listener is registered for the new connection once it becomes
282// READY.
283func (s) TestEndpointUpdate(t *testing.T) {
284 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
285 defer cancel()
286
287 srvA := startORCAServer(t)
288 srvB := startORCAServer(t)
289
290 r := manual.NewBuilderWithScheme("test")
291 cc, err := grpc.Dial(r.Scheme()+":///test",
292 grpc.WithTransportCredentials(insecure.NewCredentials()),
293 grpc.WithResolvers(r),
294 grpc.WithDefaultServiceConfig(orcaSvcConfig()),
295 )
296 if err != nil {
297 t.Fatalf("Failed to dial: %v", err)
298 }
299 defer cc.Close()
300 tc := testgrpc.NewTestServiceClient(cc)
301
302 state := resolver.State{
303 Endpoints: []resolver.Endpoint{
304 {Addresses: []resolver.Address{{Addr: srvA.Address}}},
305 },
306 }
307 r.UpdateState(state)
308
309 orcaRes := &v3orcapb.OrcaLoadReport{}
310 req := &testpb.SimpleRequest{
311 OrcaPerQueryReport: &testpb.TestOrcaReport{
312 CpuUtilization: 0.11,
313 MemoryUtilization: 0.22,
314 },
315 }
316 if _, err := tc.UnaryCall(contextWithORCAResult(ctx, &orcaRes), req); err != nil {
317 t.Fatalf("UnaryCall to srvA failed: %v", err)
318 }
319 wantA := &v3orcapb.OrcaLoadReport{CpuUtilization: 0.11, MemUtilization: 0.22}
320 if diff := cmp.Diff(orcaRes, wantA, protocmp.Transform()); diff != "" {
321 t.Fatalf("ORCA from srvA mismatch (-got +want):\n%s", diff)
322 }
323
324 // Distinctive OOB metric on srvB to confirm the switch via OOB fallback.
325 srvB.metricsRecorder.SetCPUUtilization(0.77)
326
327 state = resolver.State{
328 Endpoints: []resolver.Endpoint{
329 {Addresses: []resolver.Address{{Addr: srvB.Address}}},
330 },
331 }
332 r.UpdateState(state)
333 // No per-call report forces OOB fallback. Once srvB's metric appears,
334 // all three are confirmed: pick_first reconnected, new OOB listener
335 // registered for srvB, old one for srvA stopped.
336 wantB := &v3orcapb.OrcaLoadReport{CpuUtilization: 0.77}
337 for ; ctx.Err() == nil; <-time.After(100 * time.Millisecond) {
338 orcaRes := &v3orcapb.OrcaLoadReport{}
339 if _, err := tc.UnaryCall(contextWithORCAResult(ctx, &orcaRes), &testpb.SimpleRequest{}); err != nil {
340 continue

Callers

nothing calls this directly

Calls 15

UnaryCallMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
DialFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
startORCAServerFunction · 0.85
orcaSvcConfigFunction · 0.85
contextWithORCAResultFunction · 0.85
ErrMethod · 0.80
SchemeMethod · 0.65

Tested by

no test coverage detected