Spring Boot Version: 3.4.2 Java Version: 21
When using spring web-mvc with kotlin coroutine support, adding a filter into the security chain appears to break the test completely
Reproducer project: https://github.com/austinarbor-wk/spring-webmvc-coroutines
If you run the tests as-is, the async test succeeds. If you uncomment line 31 in SecurityConfig
(which adds a simple logging filter), then the async tests start failing.
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.4.2)
2025-02-20T12:57:36.341-05:00 INFO 12578 --- [ Test worker] dev.aga.controller.SomeControllerTest : Starting SomeControllerTest using Java 21.0.5 with PID 12578 (started by austinarbor in /Users/austinarbor/git/wk/spring-webmvc-coroutines)
2025-02-20T12:57:36.342-05:00 INFO 12578 --- [ Test worker] dev.aga.controller.SomeControllerTest : No active profile set, falling back to 1 default profile: "default"
2025-02-20T12:57:36.851-05:00 WARN 12578 --- [ Test worker] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 68b959c1-9150-4758-8799-f3a357dcbf6d
This generated password is for development use only. Your security configuration must be updated before running your application in production.
2025-02-20T12:57:36.863-05:00 INFO 12578 --- [ Test worker] r$InitializeUserDetailsManagerConfigurer : Global AuthenticationManager configured with UserDetailsService bean with name inMemoryUserDetailsManager
2025-02-20T12:57:37.118-05:00 INFO 12578 --- [ Test worker] o.s.b.t.m.w.SpringBootMockServletContext : Initializing Spring TestDispatcherServlet ''
2025-02-20T12:57:37.118-05:00 INFO 12578 --- [ Test worker] o.s.t.web.servlet.TestDispatcherServlet : Initializing Servlet ''
2025-02-20T12:57:37.119-05:00 INFO 12578 --- [ Test worker] o.s.t.web.servlet.TestDispatcherServlet : Completed initialization in 1 ms
2025-02-20T12:57:37.137-05:00 INFO 12578 --- [ Test worker] dev.aga.controller.SomeControllerTest : Started SomeControllerTest in 0.917 seconds (process running for 1.43)
2025-02-20T12:57:37.587-05:00 INFO 12578 --- [ Test worker] d.a.config.SecurityConfig$LoggingFilter : foo
MockHttpServletRequest:
HTTP Method = POST
Request URI = /endpoint
Parameters = {}
Headers = [Content-Type:"application/json;charset=UTF-8", Content-Length:"10"]
Body = {"a": "b"}
Session Attrs = {}
Handler:
Type = null
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 200
Error message = null
Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers", X-Content-Type-Options:"nosniff", X-XSS-Protection:"0", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY"]
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
Async not started
java.lang.AssertionError: Async not started
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:39)
at org.springframework.test.util.AssertionErrors.assertTrue(AssertionErrors.java:73)
at org.springframework.test.web.servlet.result.RequestResultMatchers.assertAsyncStarted(RequestResultMatchers.java:167)
at org.springframework.test.web.servlet.result.RequestResultMatchers.lambda$asyncStarted$0(RequestResultMatchers.java:70)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:214)
at org.springframework.test.web.servlet.result.RequestResultMatchersDsl.asyncStarted(RequestResultMatchersDsl.kt:36)
at dev.aga.controller.SomeControllerTest.normal___async$lambda$6$lambda$5(SomeControllerTest.kt:39)
at org.springframework.test.web.servlet.MockMvcResultMatchersDsl.request(MockMvcResultMatchersDsl.kt:34)
at dev.aga.controller.SomeControllerTest.normal___async$lambda$6(SomeControllerTest.kt:39)
at org.springframework.test.web.servlet.ResultActionsDsl.andExpect(ResultActionsDsl.kt:18)
at dev.aga.controller.SomeControllerTest.normal - async(SomeControllerTest.kt:37)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)