Skip to content

Commit 9efaa6a

Browse files
committed
S2AStub doesn't return responses at front of queue.
1 parent 59573ec commit 9efaa6a

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

s2a/src/main/java/io/grpc/s2a/handshaker/S2AStub.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ BlockingQueue<Result> getResponses() {
8484
* @throws IOException if an unexpected response is received, or if the {@code reader} or {@code
8585
* writer} calls their {@code onError} method.
8686
*/
87+
@SuppressWarnings("CheckReturnValue")
8788
public SessionResp send(SessionReq req) throws IOException, InterruptedException {
8889
if (doneWriting && doneReading) {
8990
logger.log(Level.INFO, "Stream to the S2A is closed.");
@@ -92,9 +93,8 @@ public SessionResp send(SessionReq req) throws IOException, InterruptedException
9293
createWriterIfNull();
9394
if (!responses.isEmpty()) {
9495
IOException exception = null;
95-
SessionResp resp = null;
9696
try {
97-
resp = responses.take().getResultOrThrow();
97+
responses.take().getResultOrThrow();
9898
} catch (IOException e) {
9999
exception = e;
100100
}
@@ -104,8 +104,9 @@ public SessionResp send(SessionReq req) throws IOException, InterruptedException
104104
"Received an unexpected response from a host at the S2A's address. The S2A might be"
105105
+ " unavailable."
106106
+ exception.getMessage());
107+
} else {
108+
throw new IOException("Received an unexpected response from a host at the S2A's address.");
107109
}
108-
return resp;
109110
}
110111
try {
111112
writer.onNext(req);

s2a/src/test/java/io/grpc/s2a/handshaker/S2AStubTest.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,13 @@ public void send_receiveManyUnexpectedResponse_expectResponsesEmpty() throws Exc
189189
@Test
190190
public void send_receiveDelayedResponse() throws Exception {
191191
writer.sendGetTlsConfigResp();
192-
SessionResp resp = stub.send(SessionReq.getDefaultInstance());
193-
SessionResp expected =
194-
SessionResp.newBuilder()
195-
.setGetTlsConfigurationResp(
196-
GetTlsConfigurationResp.newBuilder()
197-
.setClientTlsConfiguration(
198-
GetTlsConfigurationResp.ClientTlsConfiguration.newBuilder()
199-
.addCertificateChain(FakeWriter.LEAF_CERT)
200-
.addCertificateChain(FakeWriter.INTERMEDIATE_CERT_2)
201-
.addCertificateChain(FakeWriter.INTERMEDIATE_CERT_1)
202-
.setMinTlsVersion(TLSVersion.TLS_VERSION_1_3)
203-
.setMaxTlsVersion(TLSVersion.TLS_VERSION_1_3)
204-
.addCiphersuites(
205-
Ciphersuite.CIPHERSUITE_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
206-
.addCiphersuites(
207-
Ciphersuite.CIPHERSUITE_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384)
208-
.addCiphersuites(
209-
Ciphersuite.CIPHERSUITE_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256)))
210-
.build();
211-
assertThat(resp).ignoringRepeatedFieldOrder().isEqualTo(expected);
192+
IOException expectedException =
193+
assertThrows(IOException.class, () -> stub.send(SessionReq.getDefaultInstance()));
194+
assertThat(expectedException)
195+
.hasMessageThat()
196+
.contains("Received an unexpected response from a host at the S2A's address.");
197+
198+
assertThat(stub.getResponses()).isEmpty();
212199
}
213200

214201
@Test

0 commit comments

Comments
 (0)