DirtiesContext used with Webflux, a random port and multiple contexts causes multiple contexts to misbehave
Bug description
I'm having an issue while running tests using Webflux. Tests are set up to run on a random port and access a controller using HttpClient (I've tested and the same issue happens with WebTestClient). If there are multiple application contexts used for the tests, then @DirtiesContext annotation causes contexts not being cleared to misbehave (to stop allowing connections).
Bug reproduce
Here is the simplest dummy app I've managed to build which replicates the issue: https://github.com/Dodomix/multiple-test-contexts-bug. If you run Test1 -> Test2 -> Test3, Test3 will fail. Each test by itself passes.
Expected behavior
All tests pass.
System info
Java: Temurin 17.0.9
I've tracked this down to this call being made to ReactorResourceFactory.
It seems that reactor.netty.http.HttpResources has a shared static so I think that when Test2 stops the context it also stops the shared resources after which Test3 will fail.
@bclozel @rstoyanchev Is this a Framework bug or something we need to configure in Spring Boot. Should we be setting useGlobalResources to false?
Hello. I've the same problem using spring boot 3.2.4, and spring framework libraries version 6.1.5.
For my test, execution steps same with topic.
I had receiving this problem after migration to spring boot 3, in branch with spring boot 2 problem isn't reproduced
@philwebb I think setting useGlobalResources is the best solution here. This should only affect runtime performance for memory allocation, this shouldn't be noticeable in tests.
We're going to investigate using a post processor in the tests to change the flag.