Better disconnection tracking in tests

We're seeing lots of random test failures caused by connections that haven't been completely closed by the time the test cleanup returns.