refactor out connection tester into reusable function