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:
Larry Safran 2025-01-15 10:43:48 -08:00 committed by GitHub
parent 87c7b7a375
commit 4d8aff72dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 26 deletions

View File

@ -195,21 +195,12 @@ public class BlockingClientCallTest {
assertThat(System.currentTimeMillis() - start).isLessThan(2 * DELAY_MILLIS); assertThat(System.currentTimeMillis() - start).isLessThan(2 * DELAY_MILLIS);
} }
// write terminated // after cancel tests
biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD, biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD,
CallOptions.DEFAULT); CallOptions.DEFAULT);
start = System.currentTimeMillis(); biDiStream.cancel("cancel write", new RuntimeException("Test requested close"));
delayedCancel(biDiStream, "cancel write");
// Write interrupted by cancel // Write after cancel should throw an exception
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
try { try {
start = System.currentTimeMillis(); start = System.currentTimeMillis();
biDiStream.write(30); biDiStream.write(30);
@ -357,31 +348,19 @@ public class BlockingClientCallTest {
} }
@Test @Test
public void testWriteCompleted() throws Exception { public void testWriteAfterCloseThrows() throws Exception {
testMethod.disableAutoRequest(); testMethod.disableAutoRequest();
biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD, biDiStream = ClientCalls.blockingBidiStreamingCall(channel, BIDI_STREAMING_METHOD,
CallOptions.DEFAULT); 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 // verify new writes throw an illegalStateException
biDiStream.halfClose();
try { try {
assertFalse(biDiStream.write(2)); assertFalse(biDiStream.write(2));
fail("write did not throw an exception when called after halfClose"); fail("write did not throw an exception when called after halfClose");
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
assertThat(e.getMessage()).containsMatch("after.*halfClose.*cancel"); 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 @Test