Bug 1414882 - Require successful handshake in raise_for_port. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 08 Nov 2017 15:30:40 +0100
changeset 695743 d993213e4ac742e3a7726df45c7fd294a3d30ea3
parent 695742 c4a1424cef5f998b6a9987b0bb1200d04e232deb
child 739697 e9a17a0928b457fd5a8366a5ed2b1005ebb6aa2a
push id88528
push userbmo:hskupin@gmail.com
push dateThu, 09 Nov 2017 19:48:28 +0000
bugs1414882
milestone58.0a1
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
testing/marionette/client/marionette_driver/marionette.py
--- 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