diff --git a/testing_support/fake_repos.py b/testing_support/fake_repos.py index 493cf4174..43a72393a 100755 --- a/testing_support/fake_repos.py +++ b/testing_support/fake_repos.py @@ -88,25 +88,18 @@ def find_free_port(host, base_port): def wait_for_port_to_bind(host, port, process): - sock = socket.socket() - - if sys.platform == 'darwin': - # On Mac SnowLeopard, if we attempt to connect to the socket - # immediately, it fails with EINVAL and never gets a chance to - # connect (putting us into a hard spin and then failing). - # Linux doesn't need this. - time.sleep(0.2) - try: start = datetime.datetime.utcnow() maxdelay = datetime.timedelta(seconds=30) while (datetime.datetime.utcnow() - start) < maxdelay: + sock = socket.socket() try: sock.connect((host, port)) logging.debug('%d is now bound' % port) return except (socket.error, EnvironmentError): - pass + # Sleep a little bit to avoid spinning too much. + time.sleep(0.2) logging.debug('%d is still not bound' % port) finally: sock.close()