mirror of https://github.com/grpc/grpc-java.git
stub: Eliminate invalid test cases where different threads were calling close from the thread writing. (#11822)
* Eliminate invalid test cases where different threads were calling close from the thread writing. * Remove multi-thread cancel/write test
This commit is contained in:
parent
87c7b7a375
commit
4d8aff72dc
|
|
@ -195,21 +195,12 @@ public class BlockingClientCallTest {
|
|||
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");
|
||||
biDiStream.cancel("cancel write", new RuntimeException("Test requested close"));
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
// Write after cancel
|
||||
// Write after cancel should throw an exception
|
||||
try {
|
||||
start = System.currentTimeMillis();
|
||||
biDiStream.write(30);
|
||||
|
|
@ -357,31 +348,19 @@ public class BlockingClientCallTest {
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
|||
Loading…
Reference in New Issue