Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-12735

MockMvc PrintResultHandler asserts before result is set

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.1.4
    • Fix Version/s: 4.1.6, 4.2 RC1
    • Component/s: Test, Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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)
      

        Attachments

          Activity

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              dparrella Dan Parrella
              Last updater:
              Spring Issuemaster
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                47 weeks, 4 days ago