interop-testing: Add a configurable warmup phase to fallback test client

This commit is contained in:
apolcyn 2022-03-04 12:18:07 -08:00 committed by GitHub
parent d00e7ee375
commit 42b32c64f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 6 deletions

View File

@ -75,6 +75,7 @@ public final class GrpclbFallbackTestClient {
private String customCredentialsType; private String customCredentialsType;
private String testCase; private String testCase;
private Boolean skipNetCmd = false; private Boolean skipNetCmd = false;
private int numWarmupRpcs;
private ManagedChannel channel; private ManagedChannel channel;
private TestServiceGrpc.TestServiceBlockingStub blockingStub; private TestServiceGrpc.TestServiceBlockingStub blockingStub;
@ -111,6 +112,8 @@ public final class GrpclbFallbackTestClient {
customCredentialsType = value; customCredentialsType = value;
} else if ("skip_net_cmd".equals(key)) { } else if ("skip_net_cmd".equals(key)) {
skipNetCmd = Boolean.valueOf(value); skipNetCmd = Boolean.valueOf(value);
} else if ("num_warmup_rpcs".equals(key)) {
numWarmupRpcs = Integer.valueOf(value);
} else { } else {
System.err.println("Unknown argument: " + key); System.err.println("Unknown argument: " + key);
usage = true; usage = true;
@ -136,6 +139,10 @@ public final class GrpclbFallbackTestClient {
+ "shell command to allow setting the net config outside of the test " + "shell command to allow setting the net config outside of the test "
+ "client. Default: " + "client. Default: "
+ c.skipNetCmd + c.skipNetCmd
+ "\n --num_warmup_rpcs Number of RPCs to perform "
+ "on a separate warmup channel before the actual test runs (each warmup "
+ "RPC uses a 1 second deadline). Default: "
+ c.numWarmupRpcs
+ "\n --test_case=TEST_CASE Test case to run. Valid options are:" + "\n --test_case=TEST_CASE Test case to run. Valid options are:"
+ "\n fast_fallback_before_startup : fallback before LB connection" + "\n fast_fallback_before_startup : fallback before LB connection"
+ "\n fast_fallback_after_startup : fallback after startup due to " + "\n fast_fallback_after_startup : fallback after startup due to "
@ -197,14 +204,15 @@ public final class GrpclbFallbackTestClient {
assertEquals(0, exitCode); assertEquals(0, exitCode);
} }
private GrpclbRouteType doRpcAndGetPath(Deadline deadline) { private GrpclbRouteType doRpcAndGetPath(
TestServiceGrpc.TestServiceBlockingStub stub, Deadline deadline) {
logger.info("doRpcAndGetPath deadline: " + deadline); logger.info("doRpcAndGetPath deadline: " + deadline);
final SimpleRequest request = SimpleRequest.newBuilder() final SimpleRequest request = SimpleRequest.newBuilder()
.setFillGrpclbRouteType(true) .setFillGrpclbRouteType(true)
.build(); .build();
GrpclbRouteType result = GrpclbRouteType.GRPCLB_ROUTE_TYPE_UNKNOWN; GrpclbRouteType result = GrpclbRouteType.GRPCLB_ROUTE_TYPE_UNKNOWN;
try { try {
SimpleResponse response = blockingStub SimpleResponse response = stub
.withDeadline(deadline) .withDeadline(deadline)
.unaryCall(request); .unaryCall(request);
result = response.getGrpclbRouteType(); result = response.getGrpclbRouteType();
@ -226,7 +234,7 @@ public final class GrpclbFallbackTestClient {
boolean fallBack = false; boolean fallBack = false;
while (!fallbackDeadline.isExpired()) { while (!fallbackDeadline.isExpired()) {
GrpclbRouteType grpclbRouteType = doRpcAndGetPath( GrpclbRouteType grpclbRouteType = doRpcAndGetPath(
Deadline.after(1, TimeUnit.SECONDS)); blockingStub, Deadline.after(1, TimeUnit.SECONDS));
if (grpclbRouteType == GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND) { if (grpclbRouteType == GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND) {
throw new AssertionError("Got grpclb route type backend. Backends are " throw new AssertionError("Got grpclb route type backend. Backends are "
+ "supposed to be unreachable, so this test is broken"); + "supposed to be unreachable, so this test is broken");
@ -247,7 +255,7 @@ public final class GrpclbFallbackTestClient {
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
assertEquals( assertEquals(
GrpclbRouteType.GRPCLB_ROUTE_TYPE_FALLBACK, GrpclbRouteType.GRPCLB_ROUTE_TYPE_FALLBACK,
doRpcAndGetPath(Deadline.after(20, TimeUnit.SECONDS))); doRpcAndGetPath(blockingStub, Deadline.after(20, TimeUnit.SECONDS)));
Thread.sleep(1000); Thread.sleep(1000);
} }
} }
@ -270,7 +278,7 @@ public final class GrpclbFallbackTestClient {
initStub(); initStub();
assertEquals( assertEquals(
GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND, GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND,
doRpcAndGetPath(Deadline.after(20, TimeUnit.SECONDS))); doRpcAndGetPath(blockingStub, Deadline.after(20, TimeUnit.SECONDS)));
runShellCmd(unrouteLbAndBackendAddrsCmd); runShellCmd(unrouteLbAndBackendAddrsCmd);
final Deadline fallbackDeadline = Deadline.after(40, TimeUnit.SECONDS); final Deadline fallbackDeadline = Deadline.after(40, TimeUnit.SECONDS);
waitForFallbackAndDoRpcs(fallbackDeadline); waitForFallbackAndDoRpcs(fallbackDeadline);
@ -280,13 +288,34 @@ public final class GrpclbFallbackTestClient {
initStub(); initStub();
assertEquals( assertEquals(
GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND, GrpclbRouteType.GRPCLB_ROUTE_TYPE_BACKEND,
doRpcAndGetPath(Deadline.after(20, TimeUnit.SECONDS))); doRpcAndGetPath(blockingStub, Deadline.after(20, TimeUnit.SECONDS)));
runShellCmd(blackholeLbAndBackendAddrsCmd); runShellCmd(blackholeLbAndBackendAddrsCmd);
final Deadline fallbackDeadline = Deadline.after(40, TimeUnit.SECONDS); final Deadline fallbackDeadline = Deadline.after(40, TimeUnit.SECONDS);
waitForFallbackAndDoRpcs(fallbackDeadline); waitForFallbackAndDoRpcs(fallbackDeadline);
} }
// The purpose of this warmup method is to get potentially expensive one-per-process
// initialization out of the way, so that we can use aggressive timeouts in the actual
// test cases. Note that the warmup phase is done using a separate channel from the
// actual test cases, so that we don't affect the states of LB policies in the channel
// of the actual test case.
private void warmup() throws Exception {
logger.info("Begin warmup, performing " + numWarmupRpcs + " RPCs on the warmup channel");
ManagedChannel channel = createChannel();
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel);
for (int i = 0; i < numWarmupRpcs; i++) {
doRpcAndGetPath(stub, Deadline.after(1, TimeUnit.SECONDS));
}
try {
channel.shutdownNow();
channel.awaitTermination(1, TimeUnit.SECONDS);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
private void run() throws Exception { private void run() throws Exception {
warmup();
logger.info("Begin test case: " + testCase); logger.info("Begin test case: " + testCase);
if (testCase.equals("fast_fallback_before_startup")) { if (testCase.equals("fast_fallback_before_startup")) {
runFastFallbackBeforeStartup(); runFastFallbackBeforeStartup();