Bård Kristian
11/20/2024, 10:59 AMCREATE DATABASE ...;
and then connect to the new database by doing the regular Database.connect(dataSource, databaseConfig = databaseConfig)
. The data source is a HikariDataSource and the database is Postgres.
If we don't explicitly pass the database to the transaction then we sometimes experience a transaction using the database of a previous test. If we assign the returned database from the Database.connect
function to a global variable and pass that to the transaction, it doesn't seem to happen. It seems there's something weird happening when assigning the default database. We've also tried setting the default database on TransactionManager and it did not make a difference.
TL;DR:
This sometimes produces race conditions if you recently connected to a new database:
transaction { /* do Exposed stuff here */ }
This does not:
transaction(database) { /* do Exposed stuff here */ }
Duc
11/20/2024, 11:18 AMtransaction { /* do Exposed stuff here */ }
↑
this will use the last Database.connect's connectionBård Kristian
11/20/2024, 1:27 PMDaniel Pitts
11/20/2024, 2:52 PMtransaction
without it.Bård Kristian
11/20/2024, 2:57 PMprivate lateinit var database: Database
fun <T> transaction(block: Transaction.() -> T): T = transaction(database) { block() }
Daniel Pitts
11/20/2024, 3:19 PMDuc
11/21/2024, 4:02 AMChantal Loncle
11/25/2024, 6:02 PMDatabase.connect()
will be made?
> We've also tried setting the default database on TransactionManager and it did not make a difference.
If so, were you also scrapping the no-longer-needed implicit (or manually-set) default between tests? Something like, for example:
TransactionManager.closeAndUnregister(TransactionManager.defaultDatabase)
Bård Kristian
11/26/2024, 7:52 AM