diff options
author | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 08:33:18 +0000 |
---|---|---|
committer | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 08:33:18 +0000 |
commit | a9767b41a352a51371a73128f049af8957b69f80 (patch) | |
tree | 10f1a09dd88622ce512dfd679a94c369de3e4d24 /build | |
parent | f8c700bae560d44b15abd73926e3d589433f1d27 (diff) | |
download | chromium_src-a9767b41a352a51371a73128f049af8957b69f80.zip chromium_src-a9767b41a352a51371a73128f049af8957b69f80.tar.gz chromium_src-a9767b41a352a51371a73128f049af8957b69f80.tar.bz2 |
Speedup net_unittests on Android by 30%.
The Chrome test server spawner (running on the host) was sleeping way too much.
Note that ideally we should move away from polling but this still sounds like a
reasonable short term improvement.
R=bulach@chromium.org
Review URL: https://codereview.chromium.org/14767023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r-- | build/android/pylib/chrome_test_server_spawner.py | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/build/android/pylib/chrome_test_server_spawner.py b/build/android/pylib/chrome_test_server_spawner.py index 676939b..47fc4f4 100644 --- a/build/android/pylib/chrome_test_server_spawner.py +++ b/build/android/pylib/chrome_test_server_spawner.py @@ -15,6 +15,7 @@ import os import select import struct import subprocess +import sys import threading import time import urlparse @@ -45,6 +46,20 @@ SERVER_TYPES = { # The timeout (in seconds) of starting up the Python test server. TEST_SERVER_STARTUP_TIMEOUT = 10 +def _WaitUntil(predicate, max_attempts=5): + """Blocks until the provided predicate (function) is true. + + Returns: + Whether the provided predicate was satisfied once (before the timeout). + """ + sleep_time_sec = 0.025 + for attempt in xrange(1, max_attempts): + if predicate(): + return True + time.sleep(sleep_time_sec) + sleep_time_sec = min(1, sleep_time_sec * 2) # Don't wait more than 1 sec. + return False + def _CheckPortStatus(port, expected_status): """Returns True if port has expected_status. @@ -56,11 +71,12 @@ def _CheckPortStatus(port, expected_status): Returns: Returns True if the status is expected. Otherwise returns False. """ - for timeout in range(1, 5): - if ports.IsHostPortUsed(port) == expected_status: - return True - time.sleep(timeout) - return False + return _WaitUntil(lambda: ports.IsHostPortUsed(port) == expected_status) + + +def _CheckDevicePortStatus(adb, port): + """Returns whether the provided port is used.""" + return _WaitUntil(lambda: ports.IsDevicePortUsed(adb, port)) def _GetServerTypeCommandLine(server_type): @@ -230,18 +246,13 @@ class TestServerThread(threading.Thread): self.is_ready = False device_port = self._test_server_forwarder.DevicePortForHostPort( self.host_port) - if device_port: - for timeout in range(1, 5): - if ports.IsDevicePortUsed(self.adb, device_port, 'LISTEN'): - self.is_ready = True - self.forwarder_device_port = device_port - break - time.sleep(timeout) + if device_port and _CheckDevicePortStatus(self.adb, device_port): + self.is_ready = True + self.forwarder_device_port = device_port # Wake up the request handler thread. self.ready_event.set() # Keep thread running until Stop() gets called. - while not self.stop_flag: - time.sleep(1) + _WaitUntil(lambda: self.stop_flag, max_attempts=sys.maxint) if self.process.poll() is None: self.process.kill() if self._test_server_forwarder: @@ -401,7 +412,6 @@ class SpawningServer(object): listener_thread = threading.Thread(target=self._Listen) listener_thread.setDaemon(True) listener_thread.start() - time.sleep(1) def Stop(self): """Stops the test server spawner. |