Commit 97aab3b0 authored by shadi@chromium.org's avatar shadi@chromium.org

Clean up ports allocated by perf windows tests on CNS external server.


BUG=141537
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/10831249

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151959 0039d316-1c4b-4281-b951-d872f2087c98
parent 1d8b79a2
...@@ -15,7 +15,6 @@ import urllib2 ...@@ -15,7 +15,6 @@ import urllib2
import pyauto import pyauto
import pyauto_paths import pyauto_paths
WINDOWS = 'win32' in sys.platform
# List of commonly used network constraints settings. # List of commonly used network constraints settings.
# Each setting is a tuppe of the form: # Each setting is a tuppe of the form:
...@@ -43,11 +42,19 @@ _CNS_PATH = os.path.join( ...@@ -43,11 +42,19 @@ _CNS_PATH = os.path.join(
# Port to start the CNS on. # Port to start the CNS on.
_CNS_PORT = 9000 _CNS_PORT = 9000
# A flag to determine whether to launch a local CNS instance or to connect
# to the external CNS server. Default to False since all current bots use an
# external instance.
# If not on Windows, set USE_LOCAL_CNS=1 env variable to switch the flag.
USE_LOCAL_CNS = ('win' not in sys.platform and 'USE_LOCAL_CNS' in os.environ and
os.environ['USE_LOCAL_CNS'] == '1')
# Base CNS URL, only requires & separated parameter names appended. # Base CNS URL, only requires & separated parameter names appended.
if WINDOWS: if USE_LOCAL_CNS:
CNS_BASE_URL = 'http://chromeperf34:%d/ServeConstrained?' % _CNS_PORT
else:
CNS_BASE_URL = 'http://127.0.0.1:%d/ServeConstrained?' % _CNS_PORT CNS_BASE_URL = 'http://127.0.0.1:%d/ServeConstrained?' % _CNS_PORT
else:
CNS_BASE_URL = 'http://chromeperf34:%d/ServeConstrained?' % _CNS_PORT
CNS_CLEANUP_URL = 'http://chromeperf34:%d/Cleanup' % _CNS_PORT
# Used for server sanity check. # Used for server sanity check.
_TEST_VIDEO = 'roller.webm' _TEST_VIDEO = 'roller.webm'
...@@ -75,12 +82,12 @@ class CNSTestBase(pyauto.PyUITest): ...@@ -75,12 +82,12 @@ class CNSTestBase(pyauto.PyUITest):
def setUp(self): def setUp(self):
"""Ensures the Constrained Network Server (CNS) server is up and running.""" """Ensures the Constrained Network Server (CNS) server is up and running."""
if WINDOWS: if USE_LOCAL_CNS:
self._SetUpWin() self._SetUpLocal()
else: else:
self._SetUpLinux() self._SetUpExternal()
def _SetUpWin(self): def _SetUpExternal(self):
"""Ensures the test can connect to the external CNS server.""" """Ensures the test can connect to the external CNS server."""
if self.WaitUntil(self._CanAccessServer, retry_sleep=3, timeout=30, if self.WaitUntil(self._CanAccessServer, retry_sleep=3, timeout=30,
debug=False): debug=False):
...@@ -88,7 +95,7 @@ class CNSTestBase(pyauto.PyUITest): ...@@ -88,7 +95,7 @@ class CNSTestBase(pyauto.PyUITest):
else: else:
self.fail('Failed to connect to CNS.') self.fail('Failed to connect to CNS.')
def _SetUpLinux(self): def _SetUpLocal(self):
"""Starts the CNS server locally.""" """Starts the CNS server locally."""
cmd = [sys.executable, os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH), cmd = [sys.executable, os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH),
'--port', str(self._port), '--port', str(self._port),
...@@ -122,8 +129,7 @@ class CNSTestBase(pyauto.PyUITest): ...@@ -122,8 +129,7 @@ class CNSTestBase(pyauto.PyUITest):
def tearDown(self): def tearDown(self):
"""Stops the Constrained Network Server (CNS).""" """Stops the Constrained Network Server (CNS)."""
pyauto.PyUITest.tearDown(self) if USE_LOCAL_CNS:
if not WINDOWS:
logging.debug('Stopping CNS server.') logging.debug('Stopping CNS server.')
# Do not use process.kill(), it will not clean up cns. # Do not use process.kill(), it will not clean up cns.
self.Kill(self._cns_process.pid) self.Kill(self._cns_process.pid)
...@@ -131,6 +137,10 @@ class CNSTestBase(pyauto.PyUITest): ...@@ -131,6 +137,10 @@ class CNSTestBase(pyauto.PyUITest):
self._cns_process.wait() self._cns_process.wait()
self.assertFalse(self._cns_process.returncode is None) self.assertFalse(self._cns_process.returncode is None)
logging.debug('CNS server stopped.') logging.debug('CNS server stopped.')
else:
# Call CNS Cleanup to remove all ports created by this client.
self.NavigateToURL(CNS_CLEANUP_URL)
pyauto.PyUITest.tearDown(self)
class ProcessLogger(threading.Thread): class ProcessLogger(threading.Thread):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment