Test connection before reconnecting.

Try to close if test fails.