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: Increase speed of fallback test #11808

Merged
merged 1 commit into from
Jan 10, 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
21 changes: 16 additions & 5 deletions xds/src/test/java/io/grpc/xds/XdsClientFallbackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,13 @@ private static void verifyNoSubscribers(ControlPlaneRule rule) {

// This test takes a long time because of the 16 sec timeout for non-existent resource
@Test
public void connect_then_mainServerDown_fallbackServerUp() throws InterruptedException {
public void connect_then_mainServerDown_fallbackServerUp() throws Exception {
mainXdsServer.restartXdsServer();
fallbackServer.restartXdsServer();
xdsClient = xdsClientPool.getObject();
XdsClientImpl xdsClient = CommonBootstrapperTestUtils.createXdsClient(
new GrpcBootstrapperImpl().bootstrap(defaultBootstrapOverride()),
DEFAULT_XDS_TRANSPORT_FACTORY, fakeClock, new ExponentialBackoffPolicy.Provider(),
MessagePrinter.INSTANCE, xdsClientMetricReporter);

xdsClient.watchXdsResource(XdsListenerResource.getInstance(), MAIN_SERVER, ldsWatcher);

Expand All @@ -349,7 +352,12 @@ public void connect_then_mainServerDown_fallbackServerUp() throws InterruptedExc
verify(rdsWatcher, timeout(5000)).onChanged(any());

mainXdsServer.getServer().shutdownNow();
TimeUnit.SECONDS.sleep(5); // TODO(lsafran) Use FakeClock so test runs faster
// Sleep for the ADS stream disconnect to be processed and for the retry to fail. Between those
// two sleeps we need the fakeClock to progress by 1 second to restart the ADS stream.
for (int i = 0; i < 5; i++) {
fakeClock.forwardTime(1000, TimeUnit.MILLISECONDS);
TimeUnit.SECONDS.sleep(1);
}

// Shouldn't do fallback since all watchers are loaded
verify(ldsWatcher, never()).onChanged(
Expand All @@ -372,7 +380,7 @@ public void connect_then_mainServerDown_fallbackServerUp() throws InterruptedExc
XdsListenerResource.LdsUpdate.forApiListener(FALLBACK_HTTP_CONNECTION_MANAGER));
verify(ldsWatcher2, timeout(5000)).onChanged(
XdsListenerResource.LdsUpdate.forApiListener(FALLBACK_HTTP_CONNECTION_MANAGER));
verify(cdsWatcher, timeout(16000)).onChanged(any());
verify(cdsWatcher, timeout(5000)).onChanged(any());

xdsClient.watchXdsResource(
XdsRouteConfigureResource.getInstance(), FALLBACK_RDS_NAME, rdsWatcher3);
Expand All @@ -381,7 +389,10 @@ public void connect_then_mainServerDown_fallbackServerUp() throws InterruptedExc
// Test that resource defined in main but not fallback is handled correctly
xdsClient.watchXdsResource(
XdsClusterResource.getInstance(), CLUSTER_NAME, cdsWatcher2);
verify(cdsWatcher2, timeout(16000)).onResourceDoesNotExist(eq(CLUSTER_NAME));
verify(cdsWatcher2, never()).onResourceDoesNotExist(eq(CLUSTER_NAME));
fakeClock.forwardTime(15000, TimeUnit.MILLISECONDS); // Does not exist timer
verify(cdsWatcher2, timeout(5000)).onResourceDoesNotExist(eq(CLUSTER_NAME));
xdsClient.shutdown();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.grpc.internal.BackoffPolicy;
import io.grpc.internal.FakeClock;
import io.grpc.internal.JsonParser;
import io.grpc.internal.TimeProvider;
import io.grpc.xds.client.Bootstrapper.ServerInfo;
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
import io.grpc.xds.internal.security.TlsContextManagerImpl;
Expand All @@ -32,28 +31,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

public class CommonBootstrapperTestUtils {
private static final ChannelCredentials CHANNEL_CREDENTIALS = InsecureChannelCredentials.create();
private static final String SERVER_URI_CUSTOM_AUTHORITY = "trafficdirector2.googleapis.com";
private static final String SERVER_URI_EMPTY_AUTHORITY = "trafficdirector3.googleapis.com";

private static final long TIME_INCREMENT = TimeUnit.SECONDS.toNanos(1);

/** Fake time provider increments time TIME_INCREMENT each call. */
private static TimeProvider newTimeProvider() {
return new TimeProvider() {
private long count;

@Override
public long currentTimeNanos() {
return ++count * TIME_INCREMENT;
}
};
}

private static final String FILE_WATCHER_CONFIG = "{\"path\": \"/etc/secret/certs\"}";
private static final String MESHCA_CONFIG =
"{\n"
Expand Down Expand Up @@ -183,14 +166,28 @@ public static XdsClientImpl createXdsClient(List<String> serverUris,
BackoffPolicy.Provider backoffPolicyProvider,
MessagePrettyPrinter messagePrinter,
XdsClientMetricReporter xdsClientMetricReporter) {
Bootstrapper.BootstrapInfo bootstrapInfo = buildBootStrap(serverUris);
return createXdsClient(
buildBootStrap(serverUris),
xdsTransportFactory,
fakeClock,
backoffPolicyProvider,
messagePrinter,
xdsClientMetricReporter);
}

public static XdsClientImpl createXdsClient(Bootstrapper.BootstrapInfo bootstrapInfo,
XdsTransportFactory xdsTransportFactory,
FakeClock fakeClock,
BackoffPolicy.Provider backoffPolicyProvider,
MessagePrettyPrinter messagePrinter,
XdsClientMetricReporter xdsClientMetricReporter) {
return new XdsClientImpl(
xdsTransportFactory,
bootstrapInfo,
fakeClock.getScheduledExecutorService(),
backoffPolicyProvider,
fakeClock.getStopwatchSupplier(),
newTimeProvider(),
larry-safran marked this conversation as resolved.
Show resolved Hide resolved
fakeClock.getTimeProvider(),
messagePrinter,
new TlsContextManagerImpl(bootstrapInfo),
xdsClientMetricReporter);
Expand Down
Loading