Skip to content

Commit af7efeb

Browse files
committed
core: Rely on ping-pong for flow control testing
The previous code did a ping-pong to make sure the transport had enough time to process, but then proceeded to sleep 5 seconds. That sleep would have been needed without the ping-pong, but with the ping-pong we are confident all events have been drained from the transport. Deleting the unnecessary sleeps saves 10 seconds, for each of the 9 instances of this test.
1 parent ebc6d3e commit af7efeb

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

core/src/testFixtures/java/io/grpc/internal/AbstractTransportTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ public void flowControlPushBack() throws Exception {
14491449
clientStream.flush();
14501450
clientStream.halfClose();
14511451
doPingPong(serverListener);
1452-
assertFalse(serverStreamListener.awaitHalfClosed(TIMEOUT_MS, TimeUnit.MILLISECONDS));
1452+
assertFalse(serverStreamListener.isHalfClosed());
14531453

14541454
serverStream.request(1);
14551455
serverReceived += verifyMessageCountAndClose(serverStreamListener.messageQueue, 1);
@@ -1461,11 +1461,7 @@ public void flowControlPushBack() throws Exception {
14611461
Status status = Status.OK.withDescription("... quite a lengthy discussion");
14621462
serverStream.close(status, new Metadata());
14631463
doPingPong(serverListener);
1464-
try {
1465-
clientStreamListener.awaitClose(TIMEOUT_MS, TimeUnit.MILLISECONDS);
1466-
fail("Expected TimeoutException");
1467-
} catch (TimeoutException expectedException) {
1468-
}
1464+
assertFalse(clientStreamListener.isClosed());
14691465

14701466
clientStream.request(1);
14711467
clientReceived += verifyMessageCountAndClose(clientStreamListener.messageQueue, 1);

core/src/testFixtures/java/io/grpc/internal/ClientStreamListenerBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public Status awaitClose(int timeout, TimeUnit unit) throws Exception {
4343
return status.get(timeout, unit);
4444
}
4545

46+
/**
47+
* Return {@code true} if {@code #awaitClose} would return immediately with a status.
48+
*/
49+
public boolean isClosed() {
50+
return status.isDone();
51+
}
52+
4653
/**
4754
* Returns response headers from the server or throws {@link
4855
* java.util.concurrent.TimeoutException} if they aren't delivered before the timeout.

core/src/testFixtures/java/io/grpc/internal/ServerStreamListenerBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public boolean awaitHalfClosed(int timeout, TimeUnit unit) throws Exception {
5454
return halfClosedLatch.await(timeout, unit);
5555
}
5656

57+
public boolean isHalfClosed() {
58+
return halfClosedLatch.getCount() == 0;
59+
}
60+
5761
public Status awaitClose(int timeout, TimeUnit unit) throws Exception {
5862
return status.get(timeout, unit);
5963
}

0 commit comments

Comments
 (0)