Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stub: Eliminate invalid test cases where different threads were calling close from the thread writing. #11822

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions stub/src/test/java/io/grpc/stub/BlockingClientCallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,12 @@ public void testCancel() throws Exception {
assertThat(System.currentTimeMillis() - start).isLessThan(2 * DELAY_MILLIS);
}

// write terminated
// after cancel tests
biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD,
CallOptions.DEFAULT);
start = System.currentTimeMillis();
delayedCancel(biDiStream, "cancel write");

// Write interrupted by cancel
try {
assertFalse(biDiStream.write(30)); // this is interrupted by cancel
fail("No exception thrown when write was interrupted by cancel");
} catch (StatusException e) {
assertEquals(Status.CANCELLED.getCode(), e.getStatus().getCode());
}
biDiStream.cancel("cancel write", new RuntimeException("Test requested close"));

// Write after cancel
// Write after cancel should throw an exception
try {
start = System.currentTimeMillis();
biDiStream.write(30);
Expand Down Expand Up @@ -357,31 +348,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
Loading