Bug 1418227 - Socket timeout is lost in TcpTransport.connect(). r=automatedtester, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Fri, 17 Nov 2017 10:15:13 +0100
changeset 444863 bf5501f121c806a37fcf6fd503074f02ab0c8380
parent 444862 4eb0dd155ef28ef6a3b55d91cfa175d0ae919b03
child 444864 eb4996243c5e9a10346995acc3ce982b9158bbe5
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1418227
milestone58.0
Bug 1418227 - Socket timeout is lost in TcpTransport.connect(). r=automatedtester, a=test-only The socket_timeout getter should not return the timeout directly from the socket instance, because right after socket.socket() it is set to "None" internally, which will cause the original value as requested by Marionette to be lost. MozReview-Commit-ID: DkmvvJ4bDF9
testing/marionette/client/marionette_driver/transport.py
testing/marionette/harness/marionette_harness/tests/unit/test_marionette.py
--- a/testing/marionette/client/marionette_driver/transport.py
+++ b/testing/marionette/client/marionette_driver/transport.py
@@ -88,36 +88,34 @@ class TcpTransport(object):
 
     On top of this protocol it uses a Marionette message format, that
     depending on the protocol level offered by the remote server, varies.
     Supported protocol levels are `min_protocol_level` and above.
     """
     max_packet_length = 4096
     min_protocol_level = 3
 
-    def __init__(self, addr, port, socket_timeout=60.0):
+    def __init__(self, host, port, socket_timeout=60.0):
         """If `socket_timeout` is `0` or `0.0`, non-blocking socket mode
         will be used.  Setting it to `1` or `None` disables timeouts on
         socket operations altogether.
         """
-        self.addr = addr
+        self._sock = None
+
+        self.host = host
         self.port = port
-        self._socket_timeout = socket_timeout
+        self.socket_timeout = socket_timeout
 
         self.protocol = self.min_protocol_level
         self.application_type = None
         self.last_id = 0
         self.expected_response = None
-        self._sock = None
 
     @property
     def socket_timeout(self):
-        if self._sock:
-            return self._sock.gettimeout()
-
         return self._socket_timeout
 
     @socket_timeout.setter
     def socket_timeout(self, value):
         self._socket_timeout = value
 
         if self._sock:
             self._sock.settimeout(value)
@@ -185,17 +183,17 @@ class TcpTransport(object):
         to receive in response.
 
         Returns a tuple of the protocol level and the application type.
         """
         try:
             self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self._sock.settimeout(self.socket_timeout)
 
-            self._sock.connect((self.addr, self.port))
+            self._sock.connect((self.host, self.port))
         except:
             # Unset so that the next attempt to send will cause
             # another connection attempt.
             self._sock = None
             raise
 
         try:
             with SocketTimeout(self._sock, 60.0):
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_marionette.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_marionette.py
@@ -46,16 +46,24 @@ class TestMarionette(MarionetteTestCase)
             self.assertRaises(socket.timeout, marionette.raise_for_port, timeout=1.0)
 
             self.marionette._send_message("acceptConnections", {"value": True})
             marionette.raise_for_port(timeout=1.0)
 
         finally:
             self.marionette._send_message("acceptConnections", {"value": True})
 
+    def test_client_socket_uses_expected_socket_timeout(self):
+        current_socket_timeout = self.marionette.socket_timeout
+
+        self.assertEqual(current_socket_timeout,
+                         self.marionette.client.socket_timeout)
+        self.assertEqual(current_socket_timeout,
+                         self.marionette.client._sock.gettimeout())
+
 
 class TestContext(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
 
     def get_context(self):