Bug 1413852 - Improve failure message for socket connection attempts.
Instead of a general socket timeout failure indicate that no hello
data has been received through the socket right after the call to
connect().
MozReview-Commit-ID: EPNiCLNyFFH
--- a/testing/marionette/client/marionette_driver/transport.py
+++ b/testing/marionette/client/marionette_driver/transport.py
@@ -1,14 +1,15 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
import socket
+import sys
import time
class SocketTimeout(object):
def __init__(self, socket, timeout):
self.sock = socket
self.timeout = timeout
self.old_timeout = None
@@ -191,20 +192,27 @@ class TcpTransport(object):
self.sock.connect((self.addr, self.port))
except:
# Unset self.sock so that the next attempt to send will cause
# another connection attempt.
self.sock = None
raise
- with SocketTimeout(self.sock, 60.0):
- # first packet is always a JSON Object
- # which we can use to tell which protocol level we are at
- raw = self.receive(unmarshal=False)
+ try:
+ with SocketTimeout(self.sock, 60.0):
+ # first packet is always a JSON Object
+ # which we can use to tell which protocol level we are at
+ raw = self.receive(unmarshal=False)
+ except socket.timeout:
+ msg = "Connection attempt failed because no data has been received over the socket: {}"
+ exc, val, tb = sys.exc_info()
+
+ raise exc, msg.format(val), tb
+
hello = json.loads(raw)
self.protocol = hello.get("marionetteProtocol", self.min_protocol_level)
self.application_type = hello.get("applicationType")
return (self.protocol, self.application_type)
def send(self, obj):
"""Send message to the remote server. Allowed input is a