title: Spring MVC test framework returning inconsistent results for async controller tests
body: <p>Using Spring MVC test frameworks standaloneSetup mode to test asynchronous methods calls, I'm getting inconsistent results. The following test can pass in my IDE, but then fail when run using ANT, but then at times will pass when run using ANT, or fail in the IDE. The contents of the second call will just return and empty string, or return the expected response. </p>
  
  <p>If I add .andDo(print) to the first call, or add a Sleep of say 500ms between the 2 mockMvc.perform calls, the test will pass.</p>
  
  <p>Has anybody else encountered this?</p>
  
  <p>Controller Route</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
  public final Callable&lt;ResponseEntity&lt;List&lt;Integer&gt;&gt;&gt; getEntries(
          @RequestParam(value = "limit", defaultValue = "100") final int limit) {
      return new Callable&lt;ResponseEntity&lt;List&lt;Integer&gt;&gt;&gt;() {
          @Override
          public ResponseEntitcany&lt;List&lt;Integer&gt;&gt; call() {
              return new ResponseEntity&lt;List&lt;Integer&gt;&gt;(service.findTopEntries(limit), HttpStatus.OK);
          }
      };
  }
  </code></pre>
  
  <p>Test</p>
  
  <pre><code>this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
  
  @Test
  public void testJSONResponse() throws Exception {
  
      MvcResult mvcResult = this.mockMvc.perform(get(this.basePath)
              .accept(MediaType.APPLICATION_JSON))
              .andReturn();
  
      this.mockMvc.perform(asyncDispatch(mvcResult))
              .andExpect(status().isOk())
              .andExpect(content().string("[]"));
  }
  </code></pre>