Skip to content

Commit

Permalink
Eliminate invalid test cases where different threads were calling clo…
Browse files Browse the repository at this point in the history
…se from the thread writing.
  • Loading branch information
larry-safran committed Jan 14, 2025
1 parent 7162d2d commit 72339da
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions stub/src/test/java/io/grpc/stub/BlockingClientCallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,31 +357,19 @@ public void testReadsAndWritesInterleaved_BlockingWrites() throws Exception {
}

@Test
public void testWriteCompleted() throws Exception {
public void testWriteAfterCloseThrows() throws Exception {
testMethod.disableAutoRequest();
biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD,
CallOptions.DEFAULT);

// Verify pending write released
long start = System.currentTimeMillis();
delayedVoidMethod(DELAY_MILLIS, biDiStream::halfClose);
assertFalse(biDiStream.write(1)); // should block until writeComplete is triggered
long end = System.currentTimeMillis();
assertThat(end - start).isAtLeast(DELAY_MILLIS);

// verify new writes throw an illegalStateException
biDiStream.halfClose();
try {
assertFalse(biDiStream.write(2));
fail("write did not throw an exception when called after halfClose");
} catch (IllegalStateException e) {
assertThat(e.getMessage()).containsMatch("after.*halfClose.*cancel");
}

// verify pending write with timeout released
biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD,
CallOptions.DEFAULT);
delayedVoidMethod(DELAY_MILLIS, biDiStream::halfClose);
assertFalse(biDiStream.write(3, 2 * DELAY_MILLIS, TimeUnit.MILLISECONDS));
}

@Test
Expand Down

0 comments on commit 72339da

Please sign in to comment.