[SPR-12735] MockMvc PrintResultHandler asserts before result is set Created: 20/Feb/15  Updated: 15/Jan/19  Resolved: 27/Feb/15

Status: Closed
Project: Spring Framework
Component/s: Test, Web
Affects Version/s: 4.1.4
Fix Version/s: 4.1.6, 4.2 RC1

Type: Bug Priority: Minor
Reporter: Dan Parrella Assignee: Rossen Stoyanchev
Resolution: Complete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Days since last comment: 1 year, 1 week, 6 days ago
Last commented by a User: true
Last updater: Spring Issuemaster


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>))


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)

Comment by Spring Issuemaster [ 14/Jan/19 ]

The Spring Framework has migrated to GitHub Issues. This issue corresponds to spring-projects/spring-framework#17332.

Generated at Mon Jan 27 06:38:18 UTC 2020 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.