-
Notifications
You must be signed in to change notification settings - Fork 41.2k
By default EmbeddedDb isn't closed in the end of context #7897
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
Comments
See #4699 which was for a similar problem with DevTools restarts |
There are a couple of workarounds. One is to use an explicit URL for the data souce, e.g.
or for h2:
Another workaround is to use devtools (just put it on the classpath) because it automatically executes Also worth bearing in mind: use |
Does the trick for our tests. But I still have to keep Not sure that it is worth to play with Dev Tools in our case, but will keep it in mind. Maybe some notes in the Reference Manual would be great? Thank you! |
- Use `messages` as a default table name - Fix JDBC test according Spring Boot 1.4 upgrade * Apply `@SpringBootTest` instead of deprecated functionality * Since `@SpringBootTest`s aren't mergeable in case of test classes hierarchy use `@TestPropertySource` for particular impl to accept its own properties * Resolve deprecations in the main classes according SCSt upgrade * Remove redundant `poller` usage in the Source definition since a default one is use implicitly any way Also see spring-attic/app-starters-release#28 - Use DB URL to force embedded usage and close it gracefully in case of `@DirtiesContext` See spring-projects/spring-boot#7897 Fixes: GH-1 (#1) Fixes: GH-3 (#3)
I got a nasty case of "works on my machine" because of test order dependence. Spring 4.3, Boot 1.5, H2. I expected I am using Spock ( |
@chrylis It's hard to say without more context. If you'd like use to take a look, please provide a small sample that reproduces the behaviour you have described. |
Just a guess - from what I've read so far, how can one be sure that As of the H2 in-memory database, it's documentation actually says that even without explicit So, long story short - what are the best practices to ensure pristine in-memory DB for every individual Test class in a typical Spring Boot application? (other than overriding |
talking to myself here.. so, if spring-boot-devtools are on the classpath, (and they are, if you run JHipster-generated microservice in "dev" profile), there's autoconfigured bean InMemoryDatabaseShutdown, which has Definitely not a bug, but still quite frustrating experience if you never gave much thought to how doSpringRunner-based tests actually work |
The same problem. Using Running simple integration test for Spring context doesn't close after all tests. HikariCP spams messages with active connections and keep JVM running...
|
The provided sample works with Spring Boot 2.3.x and 2.4.x. The earliest version where it works is 2.3.0.M1. I believe that's due to #16747 where each context now generated a unique name for the database. Setting With the change to generating unique database names by default, I think the current behaviour makes sense. |
When I build tests against EmbeddedDB (
hsqldb
), I noticed that in between@DirtiesContext
that DB isn't closed:Looks like in the
DataSourceAutoConfiguration
doesn't work because the next one
PooledDataSourceConfiguration
wins somehow.And since
spring-boot-starter-jdbc
providestomcat-jdbc
by default, that feels likeDataSourceConfiguration.Tomcat
creates aDataSource
bean.Unlike
EmbeddedDataSourceConfiguration
that case doesn't providethis.database.shutdown()
, therefore our in-memory DB stands in between@DirtiesContext
s.The simple app to demonstrate the issue: https://github.com/artembilan/EmbeddedDbDiritesContext
The text was updated successfully, but these errors were encountered: