Skip to content

Commit 7565c51

Browse files
leestana01sbrannen
authored andcommitted
Restore thread interrupt flag in DefaultMvcResult
awaitAsyncDispatch() catches InterruptedException, returns false, and discards the interruption. Catching InterruptedException without rethrowing should restore the interrupt status (as is done across the framework's main sources), so re-assert it before returning false. Closes gh-36876 Signed-off-by: leestana01 <leestana01@naver.com>
1 parent 03d80fe commit 7565c51

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ private boolean awaitAsyncDispatch(long timeout) {
153153
return this.asyncDispatchLatch.await(timeout, TimeUnit.MILLISECONDS);
154154
}
155155
catch (InterruptedException ex) {
156+
Thread.currentThread().interrupt();
156157
return false;
157158
}
158159
}

‎spring-test/src/test/java/org/springframework/test/web/servlet/DefaultMvcResultTests.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.springframework.mock.web.MockHttpServletRequest;
2424

25+
import static org.assertj.core.api.Assertions.assertThat;
2526
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
2627

2728
/**
@@ -46,4 +47,19 @@ void getAsyncResultFailure() {
4647
this.mvcResult.getAsyncResult(0));
4748
}
4849

50+
@Test
51+
void getAsyncResultRestoresInterruptStatusWhenInterrupted() {
52+
this.mvcResult.setAsyncDispatchLatch(new CountDownLatch(1));
53+
Thread.currentThread().interrupt();
54+
try {
55+
assertThatIllegalStateException().isThrownBy(() ->
56+
this.mvcResult.getAsyncResult(1000));
57+
assertThat(Thread.currentThread().isInterrupted()).isTrue();
58+
}
59+
finally {
60+
// Clear the interrupt status so it does not leak to other tests.
61+
Thread.interrupted();
62+
}
63+
}
64+
4965
}

0 commit comments

Comments
 (0)