Fixed issue in test scripts causing infinite loop if socket couldn't be connected