Fixed tests on MacOS X

Added EPIPE to expected connection errors
Refactoring