java.lang.IllegalStateException: Async result for handler [public <HIDDEN>] was not set during the specified timeToWait=0

Spring JIRA | Dan Parrella | 2 years ago
tip
Do you find the tips below useful? Click on the to mark them and say thanks to rafael . Or join the community to write better ones.
  1. 0

    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. h4. Example Code {code:java} 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()); {code} h4. Stack Trace {noformat} 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) {noformat}

    Spring JIRA | 2 years ago | Dan Parrella
    java.lang.IllegalStateException: Async result for handler [public <HIDDEN>] was not set during the specified timeToWait=0
  2. 0

    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. h4. Example Code {code:java} 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()); {code} h4. Stack Trace {noformat} 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) {noformat}

    Spring JIRA | 2 years ago | Dan Parrella
    java.lang.IllegalStateException: Async result for handler [public <HIDDEN>] was not set during the specified timeToWait=0
  3. 0
    samebug tip
    If you're using boot 1.4.x you need to modify the @springBootTest annotation to @SpringBootTest(classes = DataFlowServerConfiguration.class). 1.3.8 doesn't have this problem as well.
    via GitHub by trisberg
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    samebug tip
    Spring Boot 1.4 changed their annotation system a little. Try using the @SpringBootApplication annotation for better results.
  6. 0

    Why is ServletServerContainerFactoryBean casuing problems when testing?

    Stack Overflow | 2 years ago | M1990
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createWebSocketContainer' defined in class path resource [com/alldata/webmanager/WebSocketConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: A ServletContext is required to access the javax.websocket.server.ServerContainer instance

  1. Dunmer 1 times, last 6 days ago
  2. tvrmsmith 1 times, last 3 weeks ago
  3. SteVio1989 8 times, last 2 months ago
  4. jpvee 2 times, last 3 months ago
  5. Hronom 3 times, last 3 months ago
3 more registered users
49 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.IllegalStateException

    Async result for handler [public <HIDDEN>] was not set during the specified timeToWait=0

    at org.springframework.util.Assert.state()
  2. Spring Core
    Assert.state
    1. org.springframework.util.Assert.state(Assert.java:385)
    1 frame
  3. Spring TestContext
    MockMvc.perform
    1. org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:143)
    2. org.springframework.test.web.servlet.result.PrintingResultHandler.printAsyncResult(PrintingResultHandler.java:131)
    3. org.springframework.test.web.servlet.result.PrintingResultHandler.handle(PrintingResultHandler.java:79)
    4. org.springframework.test.web.servlet.MockMvc.applyDefaultResultActions(MockMvc.java:176)
    5. org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:146)
    5 frames