Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: tools/chrome_remote_control/chrome_remote_control/cros_browser_backend.py

Issue 11231087: Removing flake in TemporaryHTTPServer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/chrome_remote_control/chrome_remote_control/cros_browser_backend.py
diff --git a/tools/chrome_remote_control/chrome_remote_control/cros_browser_backend.py b/tools/chrome_remote_control/chrome_remote_control/cros_browser_backend.py
index 109f4c51e41c32d55afb7fd59d079d0ccbe706f9..2c6438f1b27a2f03db0d8305bed81596ce389264 100644
--- a/tools/chrome_remote_control/chrome_remote_control/cros_browser_backend.py
+++ b/tools/chrome_remote_control/chrome_remote_control/cros_browser_backend.py
@@ -4,10 +4,10 @@
import logging
import socket
import subprocess
-import time
from chrome_remote_control import browser_backend
from chrome_remote_control import cros_interface
+from chrome_remote_control import util
class CrOSBrowserBackend(browser_backend.BrowserBackend):
"""The backend for controlling a browser instance running on CrOS.
@@ -143,33 +143,54 @@ class CrOSBrowserBackend(browser_backend.BrowserBackend):
return False
return self._proc.IsAlive()
- def CreateForwarder(self, host_port):
+ def CreateForwarder(self, host_port, remote_port=None):
assert self._cri
return SSHReverseForwarder(self._cri,
- host_port)
+ host_port,
+ remote_port)
class SSHReverseForwarder(object):
- def __init__(self, cri, host_port):
+ def __init__(self, cri, host_port, remote_port=None):
self._proc = None
self._host_port = host_port
+ if remote_port is None:
+ self._remote_port = cri.GetRemotePort()
+ else:
+ self._remote_port = remote_port
self._proc = subprocess.Popen(
cri.FormSSHCommandLine(['sleep', '99999999999'],
['-R%i:localhost:%i' %
- (host_port, host_port)]),
+ (self._remote_port, host_port)]),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
shell=False)
- # TODO(nduca): How do we wait for the server to come up in a
- # robust way?
- time.sleep(1.5)
+ # IsServerUp runs python code on the remote machine which attempts to
+ # connect to the given address and port.
+ def IsServerUp(address, port):
+ pycmd = """import socket
+try:
nduca 2012/11/06 04:28:01 ssh to the target and run wget with some args. It'
hartmanng 2012/11/19 18:49:13 Done.
+ tmp = socket.socket()
nduca 2012/11/06 04:28:01 There should be a cros-interface method here... Is
hartmanng 2012/11/19 18:49:13 Done.
+ tmp.connect(('%s', %i))
+ tmp.close()
+ print True
+except:
+ print False""" % (address, port)
+
+ response = cri.RunRemotePython(pycmd)[0].strip()
+ return response == 'True'
+
+ # We wait on IsServerUp using the address and port of the forwarder we just
+ # set up, so when it succeeds we can be confident that it's fully ready on
+ # the remote end.
+ util.WaitFor(lambda: IsServerUp('localhost', self._remote_port), 60)
@property
def url(self):
assert self._proc
- return 'http://localhost:%i' % self._host_port
+ return 'http://localhost:%i' % self._remote_port
def Close(self):
if self._proc:

Powered by Google App Engine
This is Rietveld 408576698