java.lang.IllegalStateException: Gave up waiting on async result from handler [public org.springframework.web.context.request.async.DeferredResult<java.lang.String> SimpleController.handle()] to complete

Spring JIRA | Maxim Valyanskiy | 3 years ago
  1. 0

    Sometimes our tests fails with following exceptions: {code} java.lang.IllegalStateException: Gave up waiting on async result from handler [public org.springframework.web.context.request.async.DeferredResult<java.lang.String> SimpleController.handle()] to complete at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:133) at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:121) at org.springframework.test.web.servlet.result.RequestResultMatchers$3.match(RequestResultMatchers.java:94) at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:149) at SimpleControllerTest.testSimple(SimpleControllerTest.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) {code} I reproduced this problem in sample application. Complete application is available at https://github.com/maxcom/spring-test-bug.

    Spring JIRA | 3 years ago | Maxim Valyanskiy
    java.lang.IllegalStateException: Gave up waiting on async result from handler [public org.springframework.web.context.request.async.DeferredResult<java.lang.String> SimpleController.handle()] to complete
  2. 0

    Sometimes our tests fails with following exceptions: {code} java.lang.IllegalStateException: Gave up waiting on async result from handler [public org.springframework.web.context.request.async.DeferredResult<java.lang.String> SimpleController.handle()] to complete at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:133) at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:121) at org.springframework.test.web.servlet.result.RequestResultMatchers$3.match(RequestResultMatchers.java:94) at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:149) at SimpleControllerTest.testSimple(SimpleControllerTest.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) {code} I reproduced this problem in sample application. Complete application is available at https://github.com/maxcom/spring-test-bug.

    Spring JIRA | 3 years ago | Maxim Valyanskiy
    java.lang.IllegalStateException: Gave up waiting on async result from handler [public org.springframework.web.context.request.async.DeferredResult<java.lang.String> SimpleController.handle()] to complete
  3. 0

    Spring DeferredResult timeout

    Stack Overflow | 2 months ago | marknorkin
    java.lang.IllegalStateException: Async result for handler [public org.springframework.web.context.request.async.DeferredResult<org.springframework.http.ResponseEntity<org.springframework.core.io.InputStreamResource>> com.example.controller.FileController.getSomeFile()] was not set during the specified timeToWait=9223372036854775807
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 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
  6. 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

    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

      Gave up waiting on async result from handler [public org.springframework.web.context.request.async.DeferredResult<java.lang.String> SimpleController.handle()] to complete

      at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult()
    2. Spring TestContext
      MockMvc$1.andExpect
      1. org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:133)
      2. org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:121)
      3. org.springframework.test.web.servlet.result.RequestResultMatchers$3.match(RequestResultMatchers.java:94)
      4. org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:149)
      4 frames
    3. Unknown
      SimpleControllerTest.testSimple
      1. SimpleControllerTest.testSimple(SimpleControllerTest.java:35)
      1 frame
    4. Java RT
      DelegatingMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      3 frames
    5. JUnit
      RunBefores.evaluate
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      5. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      5 frames