Wiremock server becomes unresponsive when ContextCache is evicted by removeEldestEntry()
Remarks
Initially I raised this issue here and here. Then I was suggested to report it here instead.
Description
We have a project in Spring Boot (version 2.7.14) that is extensively tested and we noticed that at some point some of our tests start failing without apparent reason.
I could boil down the issue into a sample project as seen here. Run the whole test suite and the last service test will fail but it shouldn't.
After digging into the details you can find that after DefaultContextCache.this.remove(eldest.getKey(), HierarchyMode.CURRENT_LEVEL) is called within removeEldestEntry() in LruCache then something happens that makes Wiremock server to behave instable.
If we replace this logic to not remove an element but to reset the whole cache then all tests will be green. This workaround is found here.
Reproduction steps
Run the whole test suite here and the last service test will fail but it shouldn't.
Are you willing to file a PR to Spring Cloud Contract (3.1.x I guess) with a failing text and a fix (I see that you have a workaround)?
Hello, thanks for checking it! I'm not sure this workaround of mine would be a proper solution. I don't fully understand why the workaround works exactly. Somehow WireMock gets screwed when ContextCache is evicted to make it possible to add an element again. When we reset it instead of removing an element, apparently it's working fine. But I wouldn't know why.
Ok, so are you able to create a test that will break with the current implementation?
Exactly. Run the whole test suite of main branch of this repo. The last service test will fail but it shouldn't.