Skip to content

Commit

Permalink
Fix tests and some underlying bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-safran committed Mar 1, 2025
1 parent 3569db8 commit 9c896a2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import io.grpc.internal.FakeClock;
import io.grpc.internal.GrpcUtil;
import io.grpc.testing.GrpcCleanupRule;
import io.grpc.xds.XdsClusterResource.CdsUpdate;
import io.grpc.xds.XdsConfig.XdsClusterConfig;
import io.grpc.xds.XdsEndpointResource.EdsUpdate;
import io.grpc.xds.XdsListenerResource.LdsUpdate;
Expand Down Expand Up @@ -241,14 +242,14 @@ public void verify_simple_aggregate() {
testWatcher.lastConfig.getClusters();
assertThat(lastConfigClusters).hasSize(childNames.size() + 1);
StatusOr<XdsClusterConfig> rootC = lastConfigClusters.get(rootName);
XdsClusterResource.CdsUpdate rootUpdate = rootC.getValue().getClusterResource();
CdsUpdate rootUpdate = rootC.getValue().getClusterResource();
assertThat(rootUpdate.clusterType()).isEqualTo(AGGREGATE);
assertThat(rootUpdate.prioritizedClusterNames()).isEqualTo(childNames);

for (String childName : childNames) {
assertThat(lastConfigClusters).containsKey(childName);
StatusOr<XdsClusterConfig> childConfigOr = lastConfigClusters.get(childName);
XdsClusterResource.CdsUpdate childResource =
CdsUpdate childResource =
childConfigOr.getValue().getClusterResource();
assertThat(childResource.clusterType()).isEqualTo(EDS);
assertThat(childResource.edsServiceName()).isEqualTo(getEdsNameForCluster(childName));
Expand Down Expand Up @@ -332,6 +333,7 @@ public void testDelayedSubscription() {
}

@Test
// TODO fix - clusters with bad status are being suppressed instead of returned
public void testMissingCdsAndEds() {
// update config so that agg cluster references 2 existing & 1 non-existing cluster
List<String> childNames = Arrays.asList("clusterC", "clusterB", "clusterA");
Expand Down Expand Up @@ -467,7 +469,8 @@ public void testCorruptLds() {
String ldsResourceName =
"xdstp://unknown.example.com/envoy.config.listener.v3.Listener/listener1";

xdsDependencyManager = new XdsDependencyManager(xdsClient, xdsConfigWatcher, syncContext,
FakeXdsClient fakeXdsClient = new FakeXdsClient();
xdsDependencyManager = new XdsDependencyManager(fakeXdsClient, xdsConfigWatcher, syncContext,
serverName, serverName, nameResolverArgs, scheduler);

Status expectedStatus = Status.INVALID_ARGUMENT.withDescription(
Expand Down Expand Up @@ -842,12 +845,12 @@ public boolean matches(XdsConfig xdsConfig) {
}

/**
* A fake XdsClient that can be used to send errors to the dependency manager
* A fake XdsClient that can be used to send errors to the dependency manager.
*/
private class FakeXdsClient extends XdsClient {
private ResourceWatcher<LdsUpdate> ldsWatcher;
private ResourceWatcher<XdsRouteConfigureResource.RdsUpdate> rdsWatcher;
private final Map<String, List<ResourceWatcher<XdsClusterResource.CdsUpdate>>> cdsWatchers = new HashMap<>();
private final Map<String, List<ResourceWatcher<CdsUpdate>>> cdsWatchers = new HashMap<>();
private final Map<String, List<ResourceWatcher<EdsUpdate>>> edsWatchers = new HashMap<>();

private void deliverCdsResourceNotExist(String clusterName) {
Expand Down Expand Up @@ -884,7 +887,7 @@ public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> resou
try {
XdsConfig defaultConfig = XdsTestUtils.getDefaultXdsConfig(serverName);
ldsWatcher.onChanged(defaultConfig.getListener());
} catch (XdsResourceType.ResourceInvalidException| IOException e) {
} catch (XdsResourceType.ResourceInvalidException | IOException e) {
throw new RuntimeException(e);
}
});
Expand All @@ -895,13 +898,13 @@ public <T extends ResourceUpdate> void watchXdsResource(XdsResourceType<T> resou
try {
XdsConfig defaultConfig = XdsTestUtils.getDefaultXdsConfig(serverName);
rdsWatcher.onChanged(defaultConfig.getRoute());
} catch (XdsResourceType.ResourceInvalidException| IOException e) {
} catch (XdsResourceType.ResourceInvalidException | IOException e) {
throw new RuntimeException(e);
}
break;
case "CDS":
cdsWatchers.computeIfAbsent(resourceName, k -> new ArrayList<>())
.add((ResourceWatcher<XdsClusterResource.CdsUpdate>) watcher);
.add((ResourceWatcher<CdsUpdate>) watcher);
break;
case "EDS":
edsWatchers.computeIfAbsent(resourceName, k -> new ArrayList<>())
Expand All @@ -928,7 +931,7 @@ public <T extends ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T>
case "CDS":
assertThat(cdsWatchers).containsKey(resourceName);
assertThat(cdsWatchers.get(resourceName)).contains(watcher);
cdsWatchers.get(resourceName).remove((ResourceWatcher<XdsClusterResource.CdsUpdate>) watcher);
cdsWatchers.get(resourceName).remove((ResourceWatcher<CdsUpdate>) watcher);
break;
case "EDS":
assertThat(edsWatchers).containsKey(resourceName);
Expand Down

0 comments on commit 9c896a2

Please sign in to comment.