Skip to content

Commit

Permalink
Add a test for corrupt LDS
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-safran committed Jan 8, 2025
1 parent 3f59a16 commit 445bd42
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
53 changes: 53 additions & 0 deletions xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static io.grpc.xds.XdsClusterResource.CdsUpdate.ClusterType.EDS;
import static io.grpc.xds.XdsTestControlPlaneService.ADS_TYPE_URL_CDS;
import static io.grpc.xds.XdsTestControlPlaneService.ADS_TYPE_URL_EDS;
import static io.grpc.xds.XdsTestControlPlaneService.ADS_TYPE_URL_LDS;
import static io.grpc.xds.XdsTestControlPlaneService.ADS_TYPE_URL_RDS;
import static io.grpc.xds.XdsTestUtils.CLUSTER_NAME;
import static io.grpc.xds.XdsTestUtils.ENDPOINT_HOSTNAME;
Expand All @@ -29,6 +30,8 @@
import static io.grpc.xds.client.CommonBootstrapperTestUtils.SERVER_URI;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.timeout;
Expand All @@ -39,6 +42,7 @@
import com.google.protobuf.Message;
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment;
import io.envoyproxy.envoy.config.listener.v3.Listener;
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration;
import io.envoyproxy.envoy.extensions.clusters.aggregate.v3.ClusterConfig;
import io.grpc.BindableService;
Expand Down Expand Up @@ -292,6 +296,55 @@ public void testMissingCdsAndEds() {
testWatcher.verifyStats(1, 0, 0);
}

@Test
public void testMissingLds() {
xdsDependencyManager = new XdsDependencyManager(
xdsClient, xdsConfigWatcher, syncContext, serverName, "badLdsName");

fakeClock.forwardTime(16, TimeUnit.SECONDS);
verify(xdsConfigWatcher, timeout(1000)).onResourceDoesNotExist(
toContextStr(XdsListenerResource.getInstance().typeName(),"badLdsName"));

testWatcher.verifyStats(0, 0, 1);
}

@Test
public void testMissingRds() {
Listener serverListener = ControlPlaneRule.buildServerListener();
Listener clientListener =
ControlPlaneRule.buildClientListener(serverName, serverName, "badRdsName");
controlPlaneService.setXdsConfig(ADS_TYPE_URL_LDS,
ImmutableMap.of(XdsTestUtils.SERVER_LISTENER, serverListener, serverName, clientListener));

xdsDependencyManager = new XdsDependencyManager(
xdsClient, xdsConfigWatcher, syncContext, serverName, serverName);

fakeClock.forwardTime(16, TimeUnit.SECONDS);
verify(xdsConfigWatcher, timeout(1000)).onResourceDoesNotExist(
toContextStr(XdsRouteConfigureResource.getInstance().typeName(),"badRdsName"));

testWatcher.verifyStats(0, 0, 1);
}

@Test
public void testCorruptLds() {
String ldsResourceName =
"xdstp://unknown.example.com/envoy.config.listener.v3.Listener/listener1";

xdsDependencyManager = new XdsDependencyManager(
xdsClient, xdsConfigWatcher, syncContext, serverName, ldsResourceName);

Status expectedStatus = Status.INVALID_ARGUMENT.withDescription(
"Wrong configuration: xds server does not exist for resource " + ldsResourceName);
String context = toContextStr(XdsListenerResource.getInstance().typeName(), ldsResourceName);
verify(xdsConfigWatcher, timeout(1000))
.onError(eq(context), argThat(new XdsTestUtils.StatusMatcher(expectedStatus)));

fakeClock.forwardTime(16, TimeUnit.SECONDS);
testWatcher.verifyStats(0,1, 0);

}

private static String toContextStr(String type, String resourceName) {
return type + " resource: " + resourceName;
}
Expand Down
17 changes: 16 additions & 1 deletion xds/src/test/java/io/grpc/xds/XdsTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.grpc.BindableService;
import io.grpc.Context;
import io.grpc.Context.CancellationListener;
import io.grpc.Status;
import io.grpc.StatusOr;
import io.grpc.internal.JsonParser;
import io.grpc.stub.StreamObserver;
Expand All @@ -74,7 +75,7 @@ public class XdsTestUtils {
static final String RDS_NAME = "route-config.googleapis.com";
static final String CLUSTER_NAME = "cluster0";
static final String EDS_NAME = "eds-service-0";
private static final String SERVER_LISTENER = "grpc/server?udpa.resource.listening_address=";
static final String SERVER_LISTENER = "grpc/server?udpa.resource.listening_address=";
public static final String ENDPOINT_HOSTNAME = "data-host";
public static final int ENDPOINT_PORT = 1234;

Expand Down Expand Up @@ -305,4 +306,18 @@ protected void sendResponse(List<String> clusters, long loadReportIntervalNano)
responseObserver.onNext(response);
}
}

static class StatusMatcher implements ArgumentMatcher<Status> {
private final Status expectedStatus;

StatusMatcher(Status expectedStatus) {
this.expectedStatus = expectedStatus;
}

@Override
public boolean matches(Status status) {
return status != null && expectedStatus.getCode().equals(status.getCode())
&& expectedStatus.getDescription().equals(status.getDescription());
}
}
}

0 comments on commit 445bd42

Please sign in to comment.