Skip to content

Commit 0e531b9

Browse files
ludochgae-java-bot
authored andcommitted
Ensure background thread is joined in InterruptedApiCallTest.
PiperOrigin-RevId: 889005882 Change-Id: Ic3e7de62747e1566c305fd757147640d567be4d1
1 parent d008b3f commit 0e531b9

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

runtime/runtime_impl_jetty121/src/test/java/com/google/apphosting/runtime/http/InterruptedApiCallTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ public class InterruptedApiCallTest extends HttpApiProxyImplTestBase {
4040
* it only gets expected exceptions.
4141
*/
4242
@Test
43-
public void interruptedApiCall() {
43+
public void interruptedApiCall() throws InterruptedException {
4444
AtomicBoolean stop = new AtomicBoolean();
45+
Thread apiClientThread = null;
4546
try {
46-
interruptedApiCall(stop);
47+
apiClientThread = interruptedApiCall(stop);
4748
} finally {
4849
stop.set(true);
50+
if (apiClientThread != null) {
51+
apiClientThread.interrupt(); // Ensure it wakes up from any blocking call
52+
apiClientThread.join();
53+
}
4954
}
5055
}
5156

52-
private void interruptedApiCall(AtomicBoolean stop) {
57+
private Thread interruptedApiCall(AtomicBoolean stop) {
5358
HttpApiHostClient.Config interruptibleConfig =
5459
config.toBuilder()
5560
// With the Jetty client, this test occasionally gets ClosedChannelException. Since
@@ -77,6 +82,7 @@ private void interruptedApiCall(AtomicBoolean stop) {
7782
}
7883
assertThat(apiClientTask.exceptionInMakeAsyncCall.get()).isNull();
7984
assertThat(apiClientTask.exceptionInFutureGet.get()).isNull();
85+
return apiClientThread;
8086
}
8187

8288
private static class ApiClientTask implements Runnable {

runtime/runtime_impl_jetty9/src/test/java/com/google/apphosting/runtime/http/InterruptedApiCallTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ public class InterruptedApiCallTest extends HttpApiProxyImplTestBase {
4040
* it only gets expected exceptions.
4141
*/
4242
@Test
43-
public void interruptedApiCall() {
43+
public void interruptedApiCall() throws InterruptedException {
4444
AtomicBoolean stop = new AtomicBoolean();
45+
Thread apiClientThread = null;
4546
try {
46-
interruptedApiCall(stop);
47+
apiClientThread = interruptedApiCall(stop);
4748
} finally {
4849
stop.set(true);
50+
if (apiClientThread != null) {
51+
apiClientThread.interrupt(); // Ensure it wakes up from any blocking call
52+
apiClientThread.join();
53+
}
4954
}
5055
}
5156

52-
private void interruptedApiCall(AtomicBoolean stop) {
57+
private Thread interruptedApiCall(AtomicBoolean stop) {
5358
HttpApiHostClient.Config interruptibleConfig =
5459
config.toBuilder()
5560
// With the Jetty client, this test occasionally gets ClosedChannelException. Since
@@ -77,6 +82,7 @@ private void interruptedApiCall(AtomicBoolean stop) {
7782
}
7883
assertThat(apiClientTask.exceptionInMakeAsyncCall.get()).isNull();
7984
assertThat(apiClientTask.exceptionInFutureGet.get()).isNull();
85+
return apiClientThread;
8086
}
8187

8288
private static class ApiClientTask implements Runnable {

0 commit comments

Comments
 (0)