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

Code before:
	primaryLis.Restart()
	if err := waitForRPCsToReachBackend(ctx, client, backend1.Address); err != nil {
		t.Fatal(err)
	}
}

// TestXDSFallback_ThreeServerPromotion verifies that when the primary
// management server is unavailable, the system attempts to connect to the
// first fallback server, and if that is also down, to the second fallback
// server. It also ensures that the system switches back to the first fallback
// server once it becomes available again, and eventually returns to the
// primary server when it comes back online, closing connections to the
// fallback servers accordingly.
func (s) TestXDSFallback_ThreeServerPromotion(t *testing.T) {
	ctx, cancel := context.WithTimeout(context.Background(), defaultFallbackTestTimeout)
	defer cancel()

	// Create three listener wrappers for three management servers.
	primaryWrappedLis := testutils.NewListenerWrapper(t, nil)
	primaryLis := testutils.NewRestartableListener(primaryWrappedLis)

	secondary1WrappedLis := testutils.NewListenerWrapper(t, nil)
	secondary1Lis := testutils.NewRestartableListener(secondary1WrappedLis)

	secondary2WrappedLis := testutils.NewListenerWrapper(t, nil)
	secondary2Lis := testutils.NewRestartableListener(secondary2WrappedLis)

	// Start the three management servers.
	primaryManagementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: primaryLis})
	secondary1ManagementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: secondary1Lis})
	secondary2ManagementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: secondary2Lis})

	// 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 secondary1.
	secondary1ManagementServer.Update(ctx, e2e.UpdateOptions{
		NodeID:    nodeID,

Review comment (suggestion):
Nit: instead of `secondary1Xxx` and `secondary2Xxx`, you could name them as `secondaryXxx` and `tertiaryXxx`.

Code after:
	primaryLis.Restart()
	if err := waitForRPCsToReachBackend(ctx, client, backend1.Address); err != nil {
		t.Fatal(err)
	}
}

// TestXDSFallback_ThreeServerPromotion verifies that when the primary
// management server is unavailable, the system attempts to connect to the
// first fallback server, and if that is also down, to the second fallback
// server. It also ensures that the system switches back to the first fallback
// server once it becomes available again, and eventually returns to the
// primary server when it comes back online, closing connections to the
// fallback servers accordingly.
func (s) TestXDSFallback_ThreeServerPromotion(t *testing.T) {
	ctx, cancel := context.WithTimeout(context.Background(), defaultFallbackTestTimeout)
	defer cancel()

	// Create three listener wrappers for three management servers.
	primaryWrappedLis := testutils.NewListenerWrapper(t, nil)
	primaryLis := testutils.NewRestartableListener(primaryWrappedLis)

	secondaryWrappedLis := testutils.NewListenerWrapper(t, nil)
	secondaryLis := testutils.NewRestartableListener(secondaryWrappedLis)

	tertiaryWrappedLis := testutils.NewListenerWrapper(t, nil)
	tertiaryLis := testutils.NewRestartableListener(tertiaryWrappedLis)

	// Start the three management servers.
	primaryManagementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: primaryLis})
	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 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,