Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing causes many http-nio-auto threads to spawn [SPR-17263] #21796

Closed
spring-projects-issues opened this issue Sep 10, 2018 · 4 comments
Closed
Assignees
Labels

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 10, 2018

Egbert opened SPR-17263 and commented

In a test suite with many integration tests I'm experiencing some problems with many application contexts being started and remaining active.

All (integration) tests are annotated with:

@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)

When running a few hundred tests, I'm experiencing an OutOfMemoryError. After some debugging it turns out that a large amount of memory is accumulated in over 100 application contexts and bean factories.

Additionally, hundreds of threads called http-nio-auto-\*\-exec-* are created and keep running.

I tried setting

spring.test.context.cache.maxSize=1
spring.cache.type=none

in the application.properties for the test, but it seems this is not used. The method org.springframework.test.context.cache.ContextCacheUtils#retrieveMaxCacheSize also doesn't seem to be invoked ever during tests, according to my breakpoints.

Cleanup doesn't seem to be executed properly. I'm uncertain if this is a bug in my configuration or the application context cache, but I can't seem to find any similar issues anywhere.


Affects: 5.0.7

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 10, 2018

Sam Brannen commented

In order to help you, we will need a lot more information.

What version of Spring and spring-test are you using?

What testing framework are you using (e.g., JUnit 4, JUnit Jupiter, TestNG) and what version?

Are you using Spring Boot, and if so what version?

It would appear that you might be using Spring Boot since you mention application.properties.

Please note that the spring.cache.type property is a Spring Boot property for caches such as as Ehcache, JCache, etc. Consequently, this property has nothing to do with the ApplicationContext caching support in spring-test.

Similarly, the spring.test.context.cache.maxSize property must be set either as a JVM system property or as a "Spring Property" via the SpringProperties abstraction (either programmatically or via a spring.properties file in the root of the classpath).

Loading

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 10, 2018

Egbert commented

Yes, I am using Spring Boot 2.0.3.

All org.spring.framework packages (including test) are on 5.0.7.RELEASE. All org.spring.framework.boot packages are on 2.0.3.RELEASE.

The tests are ran by Maven Surefire plugin, using JUnit 4.12.

I expected spring.cache.type to not make a difference, but set it just to make sure it was not related.

I will try setting the maxSize property as a JVM system property. However, I expect that this will not help - the documentation and source indicate that the default should be 32, while I'm seeing more than a hundred contexts in the cache when analyzing the heap dump. So either the limit is not honored at all, or something else is keeping these instances alive (even though the heap dump suggests they are referenced from the application context map.

Loading

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 10, 2018

Sam Brannen commented

Thanks for the feedback on the versions, etc.

Do you have any custom configuration for Maven Surefire (forking, parallel, etc.)?

Loading

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 10, 2018

Sam Brannen commented

Also, what kind of logging output do you see if you add the following to your application.properties configuration file for Spring Boot?

logging.level.org.springframework.test.context.cache=DEBUG

You should see entries similar to the following:

2018-09-10 17:28:19.267 DEBUG 19672 --- [           main] org.springframework.test.context.cache   : Spring test ApplicationContext cache statistics: [DefaultContextCache@2a984952 size = 2, maxSize = 32, parentContextCount = 0, hitCount = 58, missCount = 2]

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants