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
java spring asynchronous spring-mvc mockmvc


source to share


No one has answered this question yet

Check out similar questions:

2480
How do I send JSON data using Curl from terminal / command line to Test Spring REST?
1898
How do you assert that a specific exception is thrown in JUnit 4 tests?
1873
What's the difference between @Component, @Repository and @Service annotations in Spring?
957
How and when to use "async and await"
470
How does Auto Wizard work in Spring?
306
Difference between spring @Controller and @RestController comments
fourteen
Spring integration tests with profile
1
Testing Spring SseEitters Integration
0
Spring HATEOAS and mockMVC ignore consumption = MediaType.APPLICATION_JSON_UTF8_VALUE
0
Quirky with Spring @Async



All Articles
Loading...
X
Show
Funny
Dev
Pics