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

Method TestLRSLogicalDNS

internal/xds/balancer/clusterimpl/tests/balancer_test.go:818–901  ·  view source on GitHub ↗

Tests that LRS works correctly in a LOGICAL_DNS cluster.

(t *testing.T)

Source from the content-addressed store, hash-verified

816
817// Tests that LRS works correctly in a LOGICAL_DNS cluster.
818func (s) TestLRSLogicalDNS(t *testing.T) {
819 // Create an xDS management server that serves ADS and LRS requests.
820 mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{SupportLoadReportingService: true})
821
822 // Create bootstrap configuration pointing to the above management server.
823 nodeID := uuid.New().String()
824 bc := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)
825
826 // Create an xDS resolver with the above bootstrap configuration.
827 resolverBuilder, err := internal.NewXDSResolverWithConfigForTesting.(func([]byte) (resolver.Builder, error))(bc)
828 if err != nil {
829 t.Fatalf("Failed to create xDS resolver for testing: %v", err)
830 }
831
832 // Start a server backend exposing the test service.
833 server := stubserver.StartTestService(t, nil)
834 defer server.Stop()
835 host, port := hostAndPortFromAddress(t, server.Address)
836
837 // Configure the xDS management server with default resources. Override the
838 // default cluster to include an LRS server config pointing to self.
839 const serviceName = "my-test-xds-service"
840 resources := e2e.DefaultClientResources(e2e.ResourceParams{
841 DialTarget: serviceName,
842 NodeID: nodeID,
843 Host: "localhost",
844 Port: testutils.ParsePort(t, server.Address),
845 SecLevel: e2e.SecurityLevelNone,
846 })
847 resources.Clusters = []*v3clusterpb.Cluster{
848 e2e.ClusterResourceWithOptions(e2e.ClusterOptions{
849 ClusterName: "cluster-" + serviceName,
850 Type: e2e.ClusterTypeLogicalDNS,
851 DNSHostName: host,
852 DNSPort: port,
853 }),
854 }
855 resources.Clusters[0].LrsServer = &v3corepb.ConfigSource{
856 ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
857 Self: &v3corepb.SelfConfigSource{},
858 },
859 }
860 resources.Endpoints = nil
861 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
862 defer cancel()
863 if err := mgmtServer.Update(ctx, resources); err != nil {
864 t.Fatal(err)
865 }
866
867 // Create a ClientConn and make a successful RPC.
868 cc, err := grpc.NewClient(fmt.Sprintf("xds:///%s", serviceName), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(resolverBuilder))
869 if err != nil {
870 t.Fatalf("failed to dial local test server: %v", err)
871 }
872 defer cc.Close()
873
874 client := testgrpc.NewTestServiceClient(cc)
875 if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil {

Callers

nothing calls this directly

Calls 15

EmptyCallMethod · 0.95
StartManagementServerFunction · 0.92
DefaultBootstrapContentsFunction · 0.92
StartTestServiceFunction · 0.92
DefaultClientResourcesFunction · 0.92
ParsePortFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92

Tested by

no test coverage detected