Flaky async spring controller tests with MockMvc

I am trying to test an async spring controller that returns a DeferredResult:

MvcResult result = mvc.perform(get("/test"))
                .andExpect(request().asyncStarted())
                .andReturn();

result = mvc.perform(asyncDispatch(result))
                .andExpect(status().is(500))
                .andReturn();

      

It usually works, but it crashes accidentally on our route.

Async started expected:<true> but was:<false>

      

And no other error comes from this AssertionError. We have several tests of this kind. Even when one test fails, others work fine during the same run.

Does anyone have an idea what might be causing this flaky behavior? I couldn't reproduce this problem locally.

+3


source to share





All Articles