Make tests more stable
Prevent writing to already closed socket, update tests