Index: chrome/test/functional/media/cns_test_base.py |
diff --git a/chrome/test/functional/media/cns_test_base.py b/chrome/test/functional/media/cns_test_base.py |
index 89bbbfbf3069f500f3b54462d4b5624df50ac7e6..6d481e2b0bfe5817b44ab94984ff745ba38eaa59 100644 |
--- a/chrome/test/functional/media/cns_test_base.py |
+++ b/chrome/test/functional/media/cns_test_base.py |
@@ -15,7 +15,6 @@ import urllib2 |
import pyauto |
import pyauto_paths |
-WINDOWS = 'win32' in sys.platform |
# List of commonly used network constraints settings. |
# Each setting is a tuppe of the form: |
@@ -43,9 +42,15 @@ _CNS_PATH = os.path.join( |
# Port to start the CNS on. |
_CNS_PORT = 9000 |
+# A flag to determine whether to launch a local CNS instance or to connect |
+# to the external CNS server. Default to True since all current bots use an |
+# external instance. Set to false when running a local test. |
+USE_EXTERNAL_SERVER = False |
DaleCurtis
2012/08/16 00:15:58
Can we make this a command line option? Also the c
shadi
2012/08/16 19:49:27
After offline discussion, we decided to use an env
|
+ |
# Base CNS URL, only requires & separated parameter names appended. |
-if WINDOWS: |
+if USE_EXTERNAL_SERVER: |
CNS_BASE_URL = 'http://chromeperf34:%d/ServeConstrained?' % _CNS_PORT |
+ CNS_CLEANUP_URL = 'http://chromeperf34:%d/Cleanup' % _CNS_PORT |
else: |
CNS_BASE_URL = 'http://127.0.0.1:%d/ServeConstrained?' % _CNS_PORT |
@@ -75,12 +80,12 @@ class CNSTestBase(pyauto.PyUITest): |
def setUp(self): |
"""Ensures the Constrained Network Server (CNS) server is up and running.""" |
- if WINDOWS: |
- self._SetUpWin() |
+ if USE_EXTERNAL_SERVER: |
+ self._SetUpExternal() |
else: |
- self._SetUpLinux() |
+ self._SetUpLocal() |
- def _SetUpWin(self): |
+ def _SetUpExternal(self): |
"""Ensures the test can connect to the external CNS server.""" |
if self.WaitUntil(self._CanAccessServer, retry_sleep=3, timeout=30, |
debug=False): |
@@ -88,7 +93,7 @@ class CNSTestBase(pyauto.PyUITest): |
else: |
self.fail('Failed to connect to CNS.') |
- def _SetUpLinux(self): |
+ def _SetUpLocal(self): |
"""Starts the CNS server locally.""" |
cmd = [sys.executable, os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH), |
'--port', str(self._port), |
@@ -122,8 +127,10 @@ class CNSTestBase(pyauto.PyUITest): |
def tearDown(self): |
"""Stops the Constrained Network Server (CNS).""" |
- pyauto.PyUITest.tearDown(self) |
- if not WINDOWS: |
+ if USE_EXTERNAL_SERVER: |
+ # Call CNS Cleanup to remove all ports created by this client. |
+ self.NavigateToURL(CNS_CLEANUP_URL) |
+ else: |
logging.debug('Stopping CNS server.') |
# Do not use process.kill(), it will not clean up cns. |
self.Kill(self._cns_process.pid) |
@@ -131,6 +138,7 @@ class CNSTestBase(pyauto.PyUITest): |
self._cns_process.wait() |
self.assertFalse(self._cns_process.returncode is None) |
logging.debug('CNS server stopped.') |
+ pyauto.PyUITest.tearDown(self) |
class ProcessLogger(threading.Thread): |