Make test for port in use more robust