Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockMvc PrintResultHandler asserts before result is set [SPR-12735] #17332

Closed
spring-issuemaster opened this issue Feb 20, 2015 · 0 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Feb 20, 2015

Dan Parrella opened SPR-12735 and commented

When running controller tests against endpoints that are asynchronous and using the PrintResultHandler, my tests always fail because the PrintResultHandler seems to attempt to print the result before it is available.

When the endpoint is asynchronous, I would expect that we wait to print until asyncDispatch(mvcResult) gets called or waiting some period of time before the result becomes available.

Example Code

final MvcResult mvcResult = getMockMvc().perform(post(<ASYNC_ENDPOINT>))
                    .andExpect(request().asyncStarted())
                    .andExpect(request().asyncResult(instanceOf(WebResponse.class)))
                    .andReturn();

getMockMvc().perform(asyncDispatch(mvcResult))
                    .andExpect(status().isOk());

Stack Trace

java.lang.IllegalStateException: Async result for handler [public <HIDDEN>] was not set during the specified timeToWait=0
	at org.springframework.util.Assert.state(Assert.java:385)
	at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:143)
	at org.springframework.test.web.servlet.result.PrintingResultHandler.printAsyncResult(PrintingResultHandler.java:131)
	at org.springframework.test.web.servlet.result.PrintingResultHandler.handle(PrintingResultHandler.java:79)
	at org.springframework.test.web.servlet.MockMvc.applyDefaultResultActions(MockMvc.java:176)
	at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:146)

Affects: 4.1.4

Referenced from: commits b4d9fb9, c48858c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.