Fork me on GitHub
#sql
<
2024-03-03
>
Vitaly Samigullin15:03:05

Q. regarding transaction rollback with next.jdbc in my integration tests. I've got a Clojure backend using ring, jetty and mount (alternative to component). In my https://github.com/pilosus/dienstplan/blob/663ca87c40e5bf77cb5ed61099cdd7ad241a4170/test/dienstplan/db_test.clj#L29 I use a transaction https://github.com/pilosus/dienstplan/blob/00026fa115a07c982f04bd0b67bd7f0f31e644fc/test/dienstplan/fixture.clj#L55 with next.jdbc.transaction/*nested-tx* :ignore binding so that I can rollback the outermost transaction during the test teardown. It works well in this scenario. In my integration tests though the whole app gets started, including jetty server, and my db rollback fixture doesn't work anymore. I'm not quite sure what's happening, but assume that it's somehow related to the Jetty server spawning multiple threads to handle connections, and my next.jdbc.transaction/*nested-tx* binding being overridden. I do have a workaround with the https://github.com/pilosus/dienstplan/blob/663ca87c40e5bf77cb5ed61099cdd7ad241a4170/test/dienstplan/fixture.clj#L82. But I find it a bit of an overkill for current tests that I have. What can I do to get my DB rollback fixture work in integration tests?

hiredman19:03:50

Wrap your handler in a call to bound-fn* when starting

hiredman19:03:25

The ultimate handler being passed to ring-jetty

Vitaly Samigullin18:03:23

Didn't know about bound-fn* . Will give it a try. Thanks!