Skip to content

Commit ba335f5

Browse files
authored
interop-test: add test case for "pick_first" picking behavior (#5554)
New fields are added to the test protos according to grpc/grpc-proto#51 This test needs to be run in an environment where "pick_first" or "grpclb" with child policy "pick_first" is configured.
1 parent 79c286e commit ba335f5

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

interop-testing/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ dependencies {
2626
libraries.truth
2727
compileOnly libraries.javax_annotation
2828
runtime libraries.opencensus_impl,
29-
libraries.netty_tcnative
29+
libraries.netty_tcnative,
30+
project(':grpc-grpclb')
3031
testCompile project(':grpc-context').sourceSets.test.output,
3132
libraries.mockito
3233
}

interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,26 @@ public void serverCompressedUnary() throws Exception {
491491
Collections.singleton(goldenResponse));
492492
}
493493

494+
/**
495+
* Assuming "pick_first" policy is used, tests that all requests are sent to the same server.
496+
*/
497+
public void pickFirstUnary() throws Exception {
498+
SimpleRequest request = SimpleRequest.newBuilder()
499+
.setResponseSize(1)
500+
.setFillServerId(true)
501+
.setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[1])))
502+
.build();
503+
504+
SimpleResponse firstResponse = blockingStub.unaryCall(request);
505+
// Increase the chance of all servers are connected, in case the channel should be doing
506+
// round_robin instead.
507+
Thread.sleep(5000);
508+
for (int i = 0; i < 100; i++) {
509+
SimpleResponse response = blockingStub.unaryCall(request);
510+
assertThat(response.getServerId()).isEqualTo(firstResponse.getServerId());
511+
}
512+
}
513+
494514
@Test
495515
public void serverStreaming() throws Exception {
496516
final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()

interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public enum TestCases {
5353
CANCEL_AFTER_BEGIN("cancel stream after starting it"),
5454
CANCEL_AFTER_FIRST_RESPONSE("cancel on first response"),
5555
TIMEOUT_ON_SLEEPING_SERVER("timeout before receiving a response"),
56-
VERY_LARGE_REQUEST("very large request");
56+
VERY_LARGE_REQUEST("very large request"),
57+
PICK_FIRST_UNARY("all requests are sent to one server despite multiple servers are resolved");
5758

5859
private final String description;
5960

interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ private void runTest(TestCases testCase) throws Exception {
377377
break;
378378
}
379379

380+
case PICK_FIRST_UNARY: {
381+
tester.pickFirstUnary();
382+
break;
383+
}
384+
380385
default:
381386
throw new IllegalArgumentException("Unknown test case: " + testCase);
382387
}

interop-testing/src/main/proto/grpc/testing/messages.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ message SimpleRequest {
6868

6969
// Whether the server should expect this request to be compressed.
7070
BoolValue expect_compressed = 8;
71+
72+
// Whether SimpleResponse should include server_id.
73+
bool fill_server_id = 9;
7174
}
7275

7376
// Unary response, as configured by the request.
@@ -79,6 +82,9 @@ message SimpleResponse {
7982
string username = 2;
8083
// OAuth scope.
8184
string oauth_scope = 3;
85+
// Server ID. This must be unique among different server instances,
86+
// but the same across all RPC's made to a particular server instance.
87+
string server_id = 4;
8288
}
8389

8490
message SimpleContext {

interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public void testCaseNamesShouldMapToEnums() {
7272
String[] additionalTestCases = {
7373
"client_compressed_unary_noprobe",
7474
"client_compressed_streaming_noprobe",
75-
"very_large_request"
75+
"very_large_request",
76+
"pick_first_unary"
7677
};
7778

7879
assertEquals(testCases.length + additionalTestCases.length, TestCases.values().length);

0 commit comments

Comments
 (0)