Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds:Cleanup to reduce test flakiness #11895

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions xds/src/main/java/io/grpc/xds/XdsDependencyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
throwIfParentContextsNotEmpty(watcher);
}

watcher.cancelled = true;
XdsResourceType<T> type = watcher.type;
String resourceName = watcher.resourceName;

Expand Down Expand Up @@ -597,6 +598,8 @@
implements ResourceWatcher<T> {
private final XdsResourceType<T> type;
private final String resourceName;
boolean cancelled;

@Nullable
private StatusOr<T> data;

Expand Down Expand Up @@ -693,6 +696,10 @@

@Override
public void onResourceDoesNotExist(String resourceName) {
if (cancelled) {
return;

Check warning on line 700 in xds/src/main/java/io/grpc/xds/XdsDependencyManager.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsDependencyManager.java#L700

Added line #L700 was not covered by tests
}

handleDoesNotExist(resourceName);
xdsConfigWatcher.onResourceDoesNotExist(toContextString());
}
Expand Down Expand Up @@ -752,6 +759,9 @@

@Override
public void onResourceDoesNotExist(String resourceName) {
if (cancelled) {
return;

Check warning on line 763 in xds/src/main/java/io/grpc/xds/XdsDependencyManager.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsDependencyManager.java#L763

Added line #L763 was not covered by tests
}
handleDoesNotExist(checkNotNull(resourceName, "resourceName"));
xdsConfigWatcher.onResourceDoesNotExist(toContextString());
}
Expand Down Expand Up @@ -836,6 +846,9 @@

@Override
public void onResourceDoesNotExist(String resourceName) {
if (cancelled) {
return;
}
handleDoesNotExist(checkNotNull(resourceName, "resourceName"));
maybePublishConfig();
}
Expand All @@ -857,6 +870,9 @@

@Override
public void onResourceDoesNotExist(String resourceName) {
if (cancelled) {
return;

Check warning on line 874 in xds/src/main/java/io/grpc/xds/XdsDependencyManager.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsDependencyManager.java#L874

Added line #L874 was not covered by tests
}
handleDoesNotExist(checkNotNull(resourceName, "resourceName"));
maybePublishConfig();
}
Expand Down
24 changes: 21 additions & 3 deletions xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.InOrder;
Expand Down Expand Up @@ -696,9 +697,9 @@ public void testChangeAggCluster() {
controlPlaneService.setXdsConfig(ADS_TYPE_URL_EDS, edsMap);

// Verify that the config is updated as expected
inOrder.verify(xdsConfigWatcher, timeout(1000)).onUpdate(xdsConfigCaptor.capture());
XdsConfig config = xdsConfigCaptor.getValue();
assertThat(config.getClusters().keySet()).containsExactly("root", "clusterA21", "clusterA22");
ClusterNameMatcher nameMatcher
= new ClusterNameMatcher(Arrays.asList("root", "clusterA21", "clusterA22"));
inOrder.verify(xdsConfigWatcher, timeout(1000)).onUpdate(argThat(nameMatcher));
}

private Listener buildInlineClientListener(String rdsName, String clusterName) {
Expand Down Expand Up @@ -789,4 +790,21 @@ void deliverLdsUpdate(long httpMaxStreamDurationNano,
});
}
}

static class ClusterNameMatcher implements ArgumentMatcher<XdsConfig> {
private final List<String> expectedNames;

ClusterNameMatcher(List<String> expectedNames) {
this.expectedNames = expectedNames;
}

@Override
public boolean matches(XdsConfig xdsConfig) {
if (xdsConfig == null || xdsConfig.getClusters() == null) {
return false;
}
return xdsConfig.getClusters().size() == expectedNames.size()
&& xdsConfig.getClusters().keySet().containsAll(expectedNames);
}
}
}