Respect async request timeout of -1 in MockMvc
When falling back on the timeout associated with the async request, a value of -1 must be treated as: never time out. Issue: SPR-16869
This commit is contained in:
@@ -154,6 +154,17 @@ public class MockAsyncContext implements AsyncContext {
|
||||
return BeanUtils.instantiateClass(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* By default this is set to 10000 (10 seconds) even though the Servlet API
|
||||
* specifies a default async request timeout of 30 seconds. Keep in mind the
|
||||
* timeout could further be impacted by global configuration through the MVC
|
||||
* Java config or the XML namespace, as well as be overridden per request on
|
||||
* {@link org.springframework.web.context.request.async.DeferredResult DeferredResult}
|
||||
* or on
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.SseEmitter SseEmitter}.
|
||||
* @param timeout the timeout value to use.
|
||||
* @see AsyncContext#setTimeout(long)
|
||||
*/
|
||||
@Override
|
||||
public void setTimeout(long timeout) {
|
||||
this.timeout = timeout;
|
||||
|
||||
@@ -138,8 +138,9 @@ class DefaultMvcResult implements MvcResult {
|
||||
|
||||
@Override
|
||||
public Object getAsyncResult(long timeToWait) {
|
||||
if (this.mockRequest.getAsyncContext() != null) {
|
||||
timeToWait = (timeToWait == -1 ? this.mockRequest.getAsyncContext().getTimeout() : timeToWait);
|
||||
if (this.mockRequest.getAsyncContext() != null && timeToWait == -1) {
|
||||
long requestTimeout = this.mockRequest.getAsyncContext().getTimeout();
|
||||
timeToWait = requestTimeout == -1 ? Long.MAX_VALUE : requestTimeout;
|
||||
}
|
||||
if (!awaitAsyncDispatch(timeToWait)) {
|
||||
throw new IllegalStateException("Async result for handler [" + this.handler + "]" +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License; Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -80,19 +80,23 @@ public interface MvcResult {
|
||||
FlashMap getFlashMap();
|
||||
|
||||
/**
|
||||
* Get the result of async execution. This method will wait for the async result
|
||||
* to be set for up to the amount of time configured on the async request,
|
||||
* i.e. {@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
|
||||
* Get the result of async execution.
|
||||
* <p>This method will wait for the async result to be set within the
|
||||
* timeout value associated with the async request, see
|
||||
* {@link org.springframework.mock.web.MockAsyncContext#setTimeout
|
||||
* MockAsyncContext#setTimeout}. Alternatively, use
|
||||
* {@link #getAsyncResult(long)} to specify the amount of time to wait.
|
||||
* @throws IllegalStateException if the async result was not set
|
||||
*/
|
||||
Object getAsyncResult();
|
||||
|
||||
/**
|
||||
* Get the result of async execution. This method will wait for the async result
|
||||
* to be set for up to the specified amount of time.
|
||||
* Get the result of async execution and wait if necessary.
|
||||
* @param timeToWait how long to wait for the async result to be set, in
|
||||
* milliseconds; if -1, then the async request timeout value is used,
|
||||
* i.e.{@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
|
||||
* milliseconds; if -1, then fall back on the timeout value associated with
|
||||
* the async request, see
|
||||
* {@link org.springframework.mock.web.MockAsyncContext#setTimeout
|
||||
* MockAsyncContext#setTimeout} for more details.
|
||||
* @throws IllegalStateException if the async result was not set
|
||||
*/
|
||||
Object getAsyncResult(long timeToWait);
|
||||
|
||||
Reference in New Issue
Block a user