Repository: grpc/grpc-go
File: xds/internal/xdsclient/tests/fallback_test.go (Go)

Code before:
	secondaryManagementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: secondaryLis})
	tertiaryManagementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: tertiaryLis})

	// Start three test service backends.
	backend1 := stubserver.StartTestService(t, nil)
	defer backend1.Stop()
	backend2 := stubserver.StartTestService(t, nil)
	defer backend2.Stop()
	backend3 := stubserver.StartTestService(t, nil)
	defer backend3.Stop()

	nodeID := uuid.New().String()
	const serviceName = "my-service-fallback-xds"

	// Configure partial resources on the primary management server.
	primaryManagementServer.Update(ctx, e2e.UpdateOptions{
		NodeID:    nodeID,
		Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(serviceName, "route-p")},
	})

	// Configure incomplete (no endpoint) resources on secondary management
	// server.
	secondaryManagementServer.Update(ctx, e2e.UpdateOptions{
		NodeID:    nodeID,
		Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(serviceName, "route-s1")},
	})

	// Configure full resources on tertiary management server.
	tertiaryManagementServer.Update(ctx, e2e.DefaultClientResources(e2e.ResourceParams{
		DialTarget: serviceName,
		NodeID:     nodeID,
		Host:       "localhost",
		Port:       testutils.ParsePort(t, backend3.Address),
		SecLevel:   e2e.SecurityLevelNone,
	}))

	// Create bootstrap configuration for all three management servers.
	bootstrapContents, err := bootstrap.NewContentsForTesting(bootstrap.ConfigOptionsForTesting{
		Servers: []byte(fmt.Sprintf(`[
            {
                "server_uri": %q,
                "channel_creds": [{"type": "insecure"}]
            },
            {
                "server_uri": %q,
                "channel_creds": [{"type": "insecure"}]
            },
             {
                "server_uri": %q,
                "channel_creds": [{"type": "insecure"}]
            }

Review comment (suggestion):
```suggestion
	// Configure partial resources on the primary and secondary
	// management servers.
	primaryManagementServer.Update(ctx, e2e.UpdateOptions{
		NodeID:    nodeID,
		Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(serviceName, "route-p")},
	})
	secondaryManagementServer.Update(ctx, e2e.UpdateOptions{
		NodeID:    nodeID,
		Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(serviceName, "route-s1")},
	})
```

Code after:
	tertiaryManagementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: tertiaryLis})

	// Start three test service backends.
	backend1 := stubserver.StartTestService(t, nil)
	defer backend1.Stop()
	backend2 := stubserver.StartTestService(t, nil)
	defer backend2.Stop()
	backend3 := stubserver.StartTestService(t, nil)
	defer backend3.Stop()

	nodeID := uuid.New().String()
	const serviceName = "my-service-fallback-xds"

	// Configure partial resources on the primary and secondary
	// management servers.
	primaryManagementServer.Update(ctx, e2e.UpdateOptions{
		NodeID:    nodeID,
		Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(serviceName, "route-p")},
	})
	secondaryManagementServer.Update(ctx, e2e.UpdateOptions{
		NodeID:    nodeID,
		Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(serviceName, "route-s1")},
	})

	// Configure full resources on tertiary management server.
	tertiaryManagementServer.Update(ctx, e2e.DefaultClientResources(e2e.ResourceParams{
		DialTarget: serviceName,
		NodeID:     nodeID,
		Host:       "localhost",
		Port:       testutils.ParsePort(t, backend3.Address),
		SecLevel:   e2e.SecurityLevelNone,
	}))

	// Create bootstrap configuration for all three management servers.
	bootstrapContents, err := bootstrap.NewContentsForTesting(bootstrap.ConfigOptionsForTesting{
		Servers: []byte(fmt.Sprintf(`[
            {
                "server_uri": %q,
                "channel_creds": [{"type": "insecure"}]
            },
            {
                "server_uri": %q,
                "channel_creds": [{"type": "insecure"}]
            },
             {
                "server_uri": %q,
                "channel_creds": [{"type": "insecure"}]
            }
        ]`, primaryManagementServer.Address, secondaryManagementServer.Address, tertiaryManagementServer.Address)),
		Node: []byte(fmt.Sprintf(`{"id": "%s"}`, nodeID)),
	})