Fix failing test

master
Rossen Stoyanchev 12 years ago
parent e14ba9dec3
commit fe77c3d5fe
  1. 30
      spring-test-mvc/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java
  2. 1
      spring-test-mvc/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java

@ -110,31 +110,33 @@ class DefaultMvcResult implements MvcResult {
} }
public Object getAsyncResult() { public Object getAsyncResult() {
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.mockRequest); HttpServletRequest request = this.mockRequest;
if (asyncManager.isConcurrentHandlingStarted()) { if (request.isAsyncStarted()) {
if (!awaitAsyncResult()) {
long timeout = request.getAsyncContext().getTimeout();
if (!awaitAsyncResult(timeout)) {
throw new IllegalStateException( throw new IllegalStateException(
"Gave up waiting on async result from [" + this.handler + "] to complete"); "Gave up waiting on async result from [" + this.handler + "] to complete");
} }
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.mockRequest);
if (asyncManager.hasConcurrentResult()) { if (asyncManager.hasConcurrentResult()) {
return asyncManager.getConcurrentResult(); return asyncManager.getConcurrentResult();
} }
} }
return null; return null;
} }
private boolean awaitAsyncResult() { private boolean awaitAsyncResult(long timeout) {
if (this.asyncResultLatch == null) { if (this.asyncResultLatch != null) {
return true; try {
} return this.asyncResultLatch.await(timeout, TimeUnit.MILLISECONDS);
long timeout = ((HttpServletRequest) this.mockRequest).getAsyncContext().getTimeout(); }
try { catch (InterruptedException e) {
return this.asyncResultLatch.await(timeout, TimeUnit.MILLISECONDS); return false;
} }
catch (InterruptedException e) {
return false;
} }
return true;
} }
} }

@ -72,7 +72,6 @@ public class AsyncTests {
public Callable<Person> getCallable() { public Callable<Person> getCallable() {
return new Callable<Person>() { return new Callable<Person>() {
public Person call() throws Exception { public Person call() throws Exception {
Thread.sleep(100);
return new Person("Joe"); return new Person("Joe");
} }
}; };

Loading…
Cancel
Save