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

@Sql annotation on tests makes schema.sql executed twice #7416

Closed
savinov opened this issue Nov 18, 2016 · 3 comments
Closed

@Sql annotation on tests makes schema.sql executed twice #7416

savinov opened this issue Nov 18, 2016 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@savinov
Copy link

savinov commented Nov 18, 2016

Sample to reproduce: https://github.com/savinov/spring-boot-schema-twice

spring-boot 1.4.1, spring-data-jpa, hsqldb (for tests). There is schema.sql and data.sql in the test resources folder. Four test classese are annotated with @RunWith(SpringRunner.class), @DataJpaTest and @Sql. One test class (SchemaTwice3Test) is annotated only with @RunWith(SpringRunner.class) and @DataJpaTest.

Run tests: mvn test

The problem is: schema.sql is executed twice somewhere between SchemaTwice3Test run and other tests run. If add (uncomment) @Sql annotation to the SchemaTwice3Test then there is no problems. If remove (comment) @Sql annotation from all the test-classes then there is no problems too.

Workarond with spring.datasource.continueOnError=true makes all the tests pass, but it's not a solution.

It seems that there is some initialization incompartability between @Sql annotation and org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 18, 2016
@philwebb philwebb added type: bug A general bug for: team-attention An issue we'd like other members of the team to review and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 16, 2016
@philwebb
Copy link
Member

philwebb commented Dec 16, 2016

This is almost certainly similar to #7524 and #7101 in that the removal of the @Sql annotation causes a new cache key. Perhaps our ImportsContextCustomizer logic could be refined again.

@wilkinsona
Copy link
Member

wilkinsona commented Jan 11, 2017

The problem doesn't occur with Spring Boot 1.4.3 because the two contexts no longer share an in-memory database. However, we believe that there shouldn't be two contexts in the first place as the SQL specified in @Sql is run in a transaction that's rolled back, i.e. it has no long term effect on the context.

@wilkinsona
Copy link
Member

We've opened #7953 to address the unnecessary creation of the second context. #7473 is the issue which means that the same database is no longer shared across the two contexts.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed for: team-attention An issue we'd like other members of the team to review type: bug A general bug labels Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants