Skip to content

Commit

Permalink
S2AStub doesn't return responses at front of queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta19 committed Sep 19, 2024
1 parent 59573ec commit 9efaa6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
7 changes: 4 additions & 3 deletions s2a/src/main/java/io/grpc/s2a/handshaker/S2AStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ BlockingQueue<Result> getResponses() {
* @throws IOException if an unexpected response is received, or if the {@code reader} or {@code
* writer} calls their {@code onError} method.
*/
@SuppressWarnings("CheckReturnValue")
public SessionResp send(SessionReq req) throws IOException, InterruptedException {
if (doneWriting && doneReading) {
logger.log(Level.INFO, "Stream to the S2A is closed.");
Expand All @@ -92,9 +93,8 @@ public SessionResp send(SessionReq req) throws IOException, InterruptedException
createWriterIfNull();
if (!responses.isEmpty()) {
IOException exception = null;
SessionResp resp = null;
try {
resp = responses.take().getResultOrThrow();
responses.take().getResultOrThrow();
} catch (IOException e) {
exception = e;
}
Expand All @@ -104,8 +104,9 @@ public SessionResp send(SessionReq req) throws IOException, InterruptedException
"Received an unexpected response from a host at the S2A's address. The S2A might be"
+ " unavailable."
+ exception.getMessage());
} else {
throw new IOException("Received an unexpected response from a host at the S2A's address.");
}
return resp;
}
try {
writer.onNext(req);
Expand Down
27 changes: 7 additions & 20 deletions s2a/src/test/java/io/grpc/s2a/handshaker/S2AStubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,13 @@ public void send_receiveManyUnexpectedResponse_expectResponsesEmpty() throws Exc
@Test
public void send_receiveDelayedResponse() throws Exception {
writer.sendGetTlsConfigResp();
SessionResp resp = stub.send(SessionReq.getDefaultInstance());
SessionResp expected =
SessionResp.newBuilder()
.setGetTlsConfigurationResp(
GetTlsConfigurationResp.newBuilder()
.setClientTlsConfiguration(
GetTlsConfigurationResp.ClientTlsConfiguration.newBuilder()
.addCertificateChain(FakeWriter.LEAF_CERT)
.addCertificateChain(FakeWriter.INTERMEDIATE_CERT_2)
.addCertificateChain(FakeWriter.INTERMEDIATE_CERT_1)
.setMinTlsVersion(TLSVersion.TLS_VERSION_1_3)
.setMaxTlsVersion(TLSVersion.TLS_VERSION_1_3)
.addCiphersuites(
Ciphersuite.CIPHERSUITE_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
.addCiphersuites(
Ciphersuite.CIPHERSUITE_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384)
.addCiphersuites(
Ciphersuite.CIPHERSUITE_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256)))
.build();
assertThat(resp).ignoringRepeatedFieldOrder().isEqualTo(expected);
IOException expectedException =
assertThrows(IOException.class, () -> stub.send(SessionReq.getDefaultInstance()));
assertThat(expectedException)
.hasMessageThat()
.contains("Received an unexpected response from a host at the S2A's address.");

assertThat(stub.getResponses()).isEmpty();
}

@Test
Expand Down

0 comments on commit 9efaa6a

Please sign in to comment.