Skip to content

Commit fe77c3d

Browse files
committed
Fix failing test
1 parent e14ba9d commit fe77c3d

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,33 @@ public void setAsyncResultLatch(CountDownLatch asyncResultLatch) {
110110
}
111111

112112
public Object getAsyncResult() {
113-
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.mockRequest);
114-
if (asyncManager.isConcurrentHandlingStarted()) {
115-
if (!awaitAsyncResult()) {
113+
HttpServletRequest request = this.mockRequest;
114+
if (request.isAsyncStarted()) {
115+
116+
long timeout = request.getAsyncContext().getTimeout();
117+
if (!awaitAsyncResult(timeout)) {
116118
throw new IllegalStateException(
117119
"Gave up waiting on async result from [" + this.handler + "] to complete");
118120
}
121+
122+
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.mockRequest);
119123
if (asyncManager.hasConcurrentResult()) {
120124
return asyncManager.getConcurrentResult();
121125
}
122126
}
123-
124127
return null;
125128
}
126129

127-
private boolean awaitAsyncResult() {
128-
if (this.asyncResultLatch == null) {
129-
return true;
130-
}
131-
long timeout = ((HttpServletRequest) this.mockRequest).getAsyncContext().getTimeout();
132-
try {
133-
return this.asyncResultLatch.await(timeout, TimeUnit.MILLISECONDS);
134-
}
135-
catch (InterruptedException e) {
136-
return false;
130+
private boolean awaitAsyncResult(long timeout) {
131+
if (this.asyncResultLatch != null) {
132+
try {
133+
return this.asyncResultLatch.await(timeout, TimeUnit.MILLISECONDS);
134+
}
135+
catch (InterruptedException e) {
136+
return false;
137+
}
137138
}
139+
return true;
138140
}
139141

140142
}

spring-test-mvc/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public DeferredResult<Person> getDeferredResult() {
7272
public Callable<Person> getCallable() {
7373
return new Callable<Person>() {
7474
public Person call() throws Exception {
75-
Thread.sleep(100);
7675
return new Person("Joe");
7776
}
7877
};

0 commit comments

Comments
 (0)