xds: Wait for sync context before assertions in federation test (#10021)

This commit is contained in:
Terry Wilson 2023-04-10 14:05:01 -07:00 committed by GitHub
parent 17e1fcb393
commit 1e028c404d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@ -125,7 +126,7 @@ public class XdsClientFederationTest {
* starts {@link LoadReportClient}s to do that.
*/
@Test
public void lrsClientsStartedForLocalityStats() throws InterruptedException {
public void lrsClientsStartedForLocalityStats() throws InterruptedException, ExecutionException {
trafficdirector.setLdsConfig(ControlPlaneRule.buildServerListener(),
ControlPlaneRule.buildClientListener("test-server"));
directpathPa.setLdsConfig(ControlPlaneRule.buildServerListener(),
@ -144,16 +145,18 @@ public class XdsClientFederationTest {
for (Entry<ServerInfo, LoadReportClient> entry : xdsClient.getServerLrsClientMap().entrySet()) {
xdsClient.addClusterLocalityStats(entry.getKey(), "clusterName", "edsServiceName",
Locality.create("", "", ""));
waitForSyncContext(xdsClient);
assertThat(entry.getValue().lrsStream).isNotNull();
}
}
/**
* Assures that when an {@link XdsClient} is asked to add cluster locality stats it appropriately
* starts {@link LoadReportClient}s to do that.
*/
@Test
public void lrsClientsStartedForDropStats() throws InterruptedException {
public void lrsClientsStartedForDropStats() throws InterruptedException, ExecutionException {
trafficdirector.setLdsConfig(ControlPlaneRule.buildServerListener(),
ControlPlaneRule.buildClientListener("test-server"));
directpathPa.setLdsConfig(ControlPlaneRule.buildServerListener(),
@ -171,6 +174,7 @@ public class XdsClientFederationTest {
// corresponding LRS client should be started
for (Entry<ServerInfo, LoadReportClient> entry : xdsClient.getServerLrsClientMap().entrySet()) {
xdsClient.addClusterDropStats(entry.getKey(), "clusterName", "edsServiceName");
waitForSyncContext(xdsClient);
assertThat(entry.getValue().lrsStream).isNotNull();
}
}
@ -203,6 +207,14 @@ public class XdsClientFederationTest {
assertThat(loadStatManagers).containsNoDuplicates();
}
// Waits for all SynchronizationContext tasks to finish, assuming no new ones get added.
private static void waitForSyncContext(XdsClient xdsClient)
throws InterruptedException, ExecutionException {
// We use this method just to have a task added to the sync context queue and wait for it to
// finish.
xdsClient.getSubscribedResourcesMetadataSnapshot().get();
}
private Map<String, ?> defaultBootstrapOverride() {
return ImmutableMap.of(
"node", ImmutableMap.of(