Bug 1414882 - Require successful handshake in raise_for_port.
In case another application is still using the port, and the
handshake with Marionette server is not successful, the
function should return immediately. Otherwise it has to continue
to wait until a successful connection has been made..
MozReview-Commit-ID: CuOMNotmCDP
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -682,44 +682,31 @@ class Marionette(object):
runner = None
if self.instance is not None:
runner = self.instance.runner
poll_interval = 0.1
starttime = datetime.datetime.now()
timeout_time = starttime + datetime.timedelta(seconds=timeout)
+ client = transport.TcpTransport(self.host, self.port, 0.5)
+
connected = False
while datetime.datetime.now() < timeout_time:
# If the instance we want to connect to is not running return immediately
if runner is not None and not runner.is_running():
break
- sock = None
try:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.settimeout(0.5)
- sock.connect((self.host, self.port))
- data = sock.recv(16)
-
- # If the application starts up very slowly (eg. Fennec on Android
- # emulator) a response package has to be received first. Otherwise
- # start_session will fail (see bug 1410366 comment 32 ff.)
- if ":" in data:
- connected = True
- break
+ client.connect()
+ return True
except socket.error:
pass
finally:
- if sock is not None:
- try:
- sock.shutdown(socket.SHUT_RDWR)
- except:
- pass
- sock.close()
+ client.close()
time.sleep(poll_interval)
if not connected:
raise socket.timeout("Timed out waiting for connection on {0}:{1}!".format(
self.host, self.port))
@do_process_check