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

Unified Diff: tools/telemetry/telemetry/cros_interface.py

Issue 11231087: Removing flake in TemporaryHTTPServer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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/telemetry/telemetry/cros_interface.py
diff --git a/tools/telemetry/telemetry/cros_interface.py b/tools/telemetry/telemetry/cros_interface.py
index 43329fbc2c0b439758ad354bea51c76c1009e26e..91a85746f8049f078de6b02eb9fe4f0412d5d6d7 100644
--- a/tools/telemetry/telemetry/cros_interface.py
+++ b/tools/telemetry/telemetry/cros_interface.py
@@ -12,8 +12,6 @@ import tempfile
from telemetry import util
-_next_remote_port = 9224
-
# TODO(nduca): This whole file is built up around making individual ssh calls
# for each operation. It really could get away with a single ssh session built
# around pexpect, I suspect, if we wanted it to be faster. But, this was
@@ -373,7 +371,24 @@ class CrOSInterface(object):
return stdout
def GetRemotePort(self):
- global _next_remote_port
- port = _next_remote_port
- _next_remote_port += 1
- return port
+ netstat = self.GetAllCmdOutput(['netstat', '-ant'])
+ netstat = netstat[0].split('\n')
+ ports_in_use = []
+
+ for line in netstat[2:]:
+ if not line:
+ continue
+ address_in_use = line.split()[3]
+ port_in_use = address_in_use.split(':')[-1]
+ ports_in_use.append(int(port_in_use))
+
+ return sorted(ports_in_use)[-1] + 1
+
+ def IsHTTPServerRunningOnPort(self, port):
+ wget_output = self.GetAllCmdOutput(
+ ['wget', 'localhost:%i' % (port), '-T1', '-t1'])
+
+ if 'Connection refused' in wget_output[1]:
+ return False
+
+ return True
« no previous file with comments | « tools/telemetry/telemetry/cros_browser_backend.py ('k') | tools/telemetry/telemetry/cros_interface_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698