-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
application-test.yaml seems to be ignored when test makes second call to DatabaseConfig.loadFromProperties #2997
Comments
Thanks for the example project with failing test. I have cloned and reproduced the issue. Some background:
The current issue as I see it is that the "Run Once Marker" is covering those things that we do really only want to run once but it is also covering the function that does the "set up the DataSourceConfig given the test docker container" we want to run our tests against. So I expect the fix for this issue to be along the lines of:
Q: Is there a workaround in the meantime? Probably look to use explicit url, username, password in application-test.yaml and programmatically set the appropriate ddl mode (which assumes we can determine when the first Ebean DatabaseFactory.create() is happening and setDdlRun(true) only for that creation). |
Maybe workaroundA possible workaround is to explicitly specify the dataSource options in application-test.yaml like: ebean:
test:
platform: postgres
dbName: test
ddlMode: dropCreate
datasource:
db:
username: test
password: test
url: jdbc:postgresql://localhost:6432/test Noting that the tests now pass but we might not be getting what we want in terms of DDL being run. If we add logging of the test output (and adjust a little so we can see when the tests create the Database instances in the logs) we see:
... and we can see the ddl being executed multiple times. This might be ok but generally it is not good when we have a bigger schema (ddl takes time) or when we desire to run tests in parallel. Generally the desire is to drop and create the db schema once for all tests. |
Background
Often when testing in Spring, multiple application contexts can be created and destroyed. When using programatic configuration of ebeans this could create a situation where multiple calls are made to DatabaseConfig.loadFromProperties method.
Expected behavior
It doesn't matter how many times the tests call DatabaseConfig.loadFromProperties, the test configuration is found and used each time.
Actual behavior
Only the first call to DatabaseConfig.loadFromProperties succeeds. When trying to use a Database created from the DatabaseConfig that was created by a second call to DatabaseConfig.loadFromProperties we get exception:
It appears as though the test configuration isn't found.
Steps to reproduce
I've created a sample project with code at https://github.com/simontankersley/programatic-ebean-test
This code fails
If you want to see a base line vs a failing test see below
Success when running a test with a single call to DatabaseConfig.loadFromProperties
gives
Failure when running a test with a multiple calls to DatabaseConfig.loadFromProperties
gives
The text was updated successfully, but these errors were encountered: