Fix tests that would be slowed by transaction leakage.

Recent changes to database shutdown mean that we now wait for transactions to finish when shutting down. This mean that each of the many tests which did not close their transactions was hanging for 20 seconds before failing.

There are still about 18 tests that leak transactions, but those do so in a way that it will not cause slow downs, I think.