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

Method TestAmbientError

internal/xds/xdsdepmgr/xds_dependency_manager_test.go:509–592  ·  view source on GitHub ↗

Tests the case where we get an ambient error and verify that we correctly log a warning for it. To make sure we get an ambient error, we send a correct update first, then send an invalid one and then send the valid resource again. We send the valid resource again so that we can be sure the ambient e

(t *testing.T)

Source from the content-addressed store, hash-verified

507// error reaches the dependency manager since there is no other way to wait for
508// it.
509func (s) TestAmbientError(t *testing.T) {
510 // Expect a warning log for the ambient error.
511 grpctest.ExpectWarning("Listener resource ambient error")
512
513 nodeID, mgmtServer, xdsClient := setupManagementServerAndClient(t, false)
514
515 watcher := newTestWatcher()
516 defer watcher.close()
517
518 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
519 defer cancel()
520
521 // Configure a valid resources.
522 resources := e2e.DefaultClientResources(e2e.ResourceParams{
523 NodeID: nodeID,
524 DialTarget: defaultTestServiceName,
525 Host: "localhost",
526 Port: 8080,
527 SecLevel: e2e.SecurityLevelNone,
528 })
529 if err := mgmtServer.Update(ctx, resources); err != nil {
530 t.Fatal(err)
531 }
532
533 dm := xdsdepmgr.New(defaultTestServiceName, defaultTestServiceName, xdsClient, watcher)
534 defer dm.Close()
535
536 // Wait for the initial valid update.
537 wantXdsConfig := xdstestutils.MakeXDSConfig(defaultTestServiceName, resources.Routes[0].Name, resources.Clusters[0].Name, resources.Clusters[0].EdsClusterConfig.ServiceName, "localhost:8080")
538 if err := xdstestutils.VerifyXDSConfig(ctx, watcher.updateCh, watcher.errorCh, wantXdsConfig); err != nil {
539 t.Fatal(err)
540 }
541
542 // Configure a listener resource that is expected to be NACKed because it
543 // does not contain the `RouteSpecifier` field in the HTTPConnectionManager.
544 // Since a valid one is already cached, this should result in an ambient
545 // error.
546 hcm := testutils.MarshalAny(t, &v3httppb.HttpConnectionManager{
547 HttpFilters: []*v3httppb.HttpFilter{e2e.HTTPFilter("router", &v3routerpb.Router{})},
548 })
549 lis := &v3listenerpb.Listener{
550 Name: defaultTestServiceName,
551 ApiListener: &v3listenerpb.ApiListener{ApiListener: hcm},
552 FilterChains: []*v3listenerpb.FilterChain{{
553 Name: "filter-chain-name",
554 Filters: []*v3listenerpb.Filter{{
555 Name: wellknown.HTTPConnectionManager,
556 ConfigType: &v3listenerpb.Filter_TypedConfig{TypedConfig: hcm},
557 }},
558 }},
559 }
560 resources.Listeners = []*v3listenerpb.Listener{lis}
561 resources.SkipValidation = true
562 if err := mgmtServer.Update(ctx, resources); err != nil {
563 t.Fatal(err)
564 }
565
566 // We expect no call to Error or Update on our watcher. We just wait for a

Callers

nothing calls this directly

Calls 11

ExpectWarningFunction · 0.92
NewFunction · 0.92
MarshalAnyFunction · 0.92
newTestWatcherFunction · 0.85
UpdateMethod · 0.65
FatalMethod · 0.65
CloseMethod · 0.65
FatalfMethod · 0.65
closeMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected