Cies Breijs
02/13/2026, 8:14 PMjdbi.transactionHandler = RollbackOnlyTransactionHandler() ) at the end of the request cycle.
During tests I'd love to open the db transaction the the start of the test, do some initialization, then pass that transaction to the "app" along the request, and after the response is back still have the transaction for in-transaction-db-inspection.
This means that instead of passing the function that creates my "app" a db connection pool, I pass it an EitherDbPoolOrOpenTransaction.
I want to give this a try, but thought I'd ask here; since I might not be the first cowboy who thinks db calls during test are acceptable 🙂 (I write a significant part of the application in Postgres -- triggers, caching tables, invariants, immutability)Andrew O'Hara
02/14/2026, 3:49 PMCies Breijs
02/16/2026, 1:55 AMCies Breijs
02/16/2026, 2:54 AMvar globalTxHandleForE2eTests: Handle? = null
sealed class DbSource {
class WrappedJdbi(val jdbi: Jdbi) : DbSource()
class WrappedTxHandleForE2eTests() : DbSource() {
fun txHandle(): Handle = globalTxHandleForE2eTests!!
}
}
Now I can use the same transaction in the @Test annotated function as is used in the HttpHandler app. It's dirty but it works and is only used in test scenarios.