From fe77c3d5fe3b498ecba7f3e1dce31f0aec43d8d6 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 26 Oct 2012 22:01:35 -0400 Subject: [PATCH] Fix failing test --- .../test/web/servlet/DefaultMvcResult.java | 30 ++++++++++--------- .../samples/standalone/AsyncTests.java | 1 - 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java b/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java index 6d89492487..6bb763bf02 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java @@ -110,31 +110,33 @@ class DefaultMvcResult implements MvcResult { } public Object getAsyncResult() { - WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.mockRequest); - if (asyncManager.isConcurrentHandlingStarted()) { - if (!awaitAsyncResult()) { + HttpServletRequest request = this.mockRequest; + if (request.isAsyncStarted()) { + + long timeout = request.getAsyncContext().getTimeout(); + if (!awaitAsyncResult(timeout)) { throw new IllegalStateException( "Gave up waiting on async result from [" + this.handler + "] to complete"); } + + WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.mockRequest); if (asyncManager.hasConcurrentResult()) { return asyncManager.getConcurrentResult(); } } - return null; } - private boolean awaitAsyncResult() { - if (this.asyncResultLatch == null) { - return true; - } - long timeout = ((HttpServletRequest) this.mockRequest).getAsyncContext().getTimeout(); - try { - return this.asyncResultLatch.await(timeout, TimeUnit.MILLISECONDS); - } - catch (InterruptedException e) { - return false; + private boolean awaitAsyncResult(long timeout) { + if (this.asyncResultLatch != null) { + try { + return this.asyncResultLatch.await(timeout, TimeUnit.MILLISECONDS); + } + catch (InterruptedException e) { + return false; + } } + return true; } } diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java index 342f02e3fe..73bdffa7c5 100644 --- a/spring-test-mvc/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java +++ b/spring-test-mvc/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java @@ -72,7 +72,6 @@ public class AsyncTests { public Callable getCallable() { return new Callable() { public Person call() throws Exception { - Thread.sleep(100); return new Person("Joe"); } };