Using a single database connection object for everything, versus continually creating new connections, seems to have resolved the socket errors I was getting while running the tests.