Fix db connection leaks in tests, closes #263.

We need to properly close the connection, transaction and inner
sub-transaction / session. Closing the connection properly returns it
to the pool.