mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-13 11:38:16 +00:00
Bug 1001322 - Move wait_for_port to transport.py and call when starting a new session. r=mdas
This commit is contained in:
parent
29b1961748
commit
469d0b2369
@ -4,12 +4,10 @@
|
||||
|
||||
import base64
|
||||
import ConfigParser
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import StringIO
|
||||
import time
|
||||
import traceback
|
||||
import warnings
|
||||
|
||||
@ -587,24 +585,9 @@ class Marionette(object):
|
||||
s.close()
|
||||
|
||||
def wait_for_port(self, timeout=60):
|
||||
starttime = datetime.datetime.now()
|
||||
poll_interval = 0.1
|
||||
while datetime.datetime.now() - starttime < datetime.timedelta(seconds=timeout):
|
||||
sock = None
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect((self.host, self.port))
|
||||
data = sock.recv(16)
|
||||
sock.close()
|
||||
if ':' in data:
|
||||
return True
|
||||
except socket.error:
|
||||
pass
|
||||
finally:
|
||||
if sock:
|
||||
sock.close()
|
||||
time.sleep(poll_interval)
|
||||
return False
|
||||
return MarionetteTransport.wait_for_port(self.host,
|
||||
self.port,
|
||||
timeout=timeout)
|
||||
|
||||
@do_crash_check
|
||||
def _send_message(self, command, response_key="ok", **kwargs):
|
||||
@ -814,15 +797,17 @@ class Marionette(object):
|
||||
'''
|
||||
return "%s%s" % (self.baseurl, relative_url)
|
||||
|
||||
def start_session(self, desired_capabilities=None, session_id=None):
|
||||
def start_session(self, desired_capabilities=None, session_id=None, timeout=60):
|
||||
"""Create a new Marionette session.
|
||||
|
||||
This method must be called before performing any other action.
|
||||
|
||||
:params desired_capabilities: An optional dict of desired
|
||||
:param desired_capabilities: An optional dict of desired
|
||||
capabilities. This is currently ignored.
|
||||
:param timeout: Timeout in seconds for the server to be ready.
|
||||
|
||||
:returns: A dict of the capabilities offered."""
|
||||
self.wait_for_port(timeout=timeout)
|
||||
self.session = self._send_message('newSession', 'value', capabilities=desired_capabilities, session_id=session_id)
|
||||
self.b2g = 'b2g' in self.session
|
||||
return self.session
|
||||
|
@ -1,4 +1,4 @@
|
||||
marionette-transport == 0.3
|
||||
marionette-transport == 0.4
|
||||
manifestparser
|
||||
mozhttpd >= 0.5
|
||||
mozinfo >= 0.7
|
||||
|
@ -2,9 +2,11 @@
|
||||
# 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 datetime
|
||||
import errno
|
||||
import json
|
||||
import socket
|
||||
import time
|
||||
|
||||
|
||||
class MarionetteTransport(object):
|
||||
@ -107,3 +109,25 @@ class MarionetteTransport(object):
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
|
||||
@staticmethod
|
||||
def wait_for_port(host, port, timeout=60):
|
||||
""" Wait for the specified Marionette host/port to be available."""
|
||||
starttime = datetime.datetime.now()
|
||||
poll_interval = 0.1
|
||||
while datetime.datetime.now() - starttime < datetime.timedelta(seconds=timeout):
|
||||
sock = None
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect((host, port))
|
||||
data = sock.recv(16)
|
||||
sock.close()
|
||||
if ':' in data:
|
||||
return True
|
||||
except socket.error:
|
||||
pass
|
||||
finally:
|
||||
if sock:
|
||||
sock.close()
|
||||
time.sleep(poll_interval)
|
||||
return False
|
||||
|
@ -1,6 +1,6 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
version = '0.3'
|
||||
version = '0.4'
|
||||
|
||||
long_description = \
|
||||
"""Marionette_ is a Mozilla project to enable remote automation in Gecko-based
|
||||
|
Loading…
x
Reference in New Issue
Block a user