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

Unified Diff: chrome/test/functional/perf_endure.py

Issue 10803002: Run Chrome Endure tests with network simulation via Web Page Replay. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Dennis' comments Created 8 years, 4 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: chrome/test/functional/perf_endure.py
diff --git a/chrome/test/functional/perf_endure.py b/chrome/test/functional/perf_endure.py
index fed79f499f00ed363d487cb579e2d3ff11c9f4d2..d9af06626e2cb84581f50d1d0b17226aff731067 100755
--- a/chrome/test/functional/perf_endure.py
+++ b/chrome/test/functional/perf_endure.py
@@ -33,12 +33,14 @@ import pyauto_utils
import remote_inspector_client
import selenium.common.exceptions
from selenium.webdriver.support.ui import WebDriverWait
+import webpagereplay
class NotSupportedEnvironmentError(RuntimeError):
"""Represent an error raised since the environment (OS) is not supported."""
pass
+
class ChromeEndureBaseTest(perf.BasePerfTest):
"""Implements common functionality for all Chrome Endure tests.
@@ -62,6 +64,26 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
_CHROME_BIN_PATH = os.path.join(perf.BasePerfTest.BrowserPath(), 'chrome')
def setUp(self):
+ # Parse the environment variable for the usage of Web Page Replay.
Nirnimesh 2012/08/06 21:36:45 please move the env parsing to a helper method so
fdeng1 2012/08/07 02:56:56 Done. move it to _ParseReplayEnv()
+ # It must be parsed before perf.BasePerfTest.setUp()
+ if 'ENDURE_NO_WPR' in os.environ:
+ self._use_wpr = False
+ logging.info('Web Page Replay is turned off as ENDURE_NO_WPR is set.')
dennis_jeffrey 2012/08/06 21:33:46 how about this to match slamm's recommended commen
fdeng1 2012/08/07 02:56:56 Done.
+ else:
+ # Do NOT manually set WPR_RECORD for the purpose of
+ # making recording archive for endure tests. Run record_endure.py instead.
+ self._is_record_mode = 'WPR_RECORD' in os.environ
+ archive_path = os.environ.get('WPR_ARCHIVE_PATH',
+ ChromeEndureReplay.Path(
+ 'archive', archive_name=self._GenArchiveName()))
+ if self._is_record_mode or os.path.exists(archive_path):
+ self._use_wpr = True
dennis_jeffrey 2012/08/06 21:33:46 log a message in this case saying something like "
fdeng1 2012/08/07 02:56:56 When WPR is successfully launched, _StartReplaySer
+ else:
+ self._use_wpr = False
+ logging.info(
+ 'Web Page Replay is turned off as the' +
+ ' archive file %s does not exist.',
slamm_google 2012/08/06 20:58:44 How about the following? Skipping Web Page Replay
fdeng1 2012/08/07 02:56:56 Done.
+ self._GenArchiveName())
# The environment variables for the Deep Memory Profiler must be set
# before perf.BasePerfTest.setUp() to inherit them to Chrome.
self._deep_memory_profile = self._GetDeepMemoryProfileEnv(
@@ -117,6 +139,7 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
self._deep_memory_profile_json_file = None
self._deep_memory_profile_last_json_filename = ''
self._deep_memory_profile_proc = None
+ self._StartReplayServerIfNecessary()
def tearDown(self):
logging.info('Terminating connection to remote inspector...')
@@ -139,6 +162,21 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
not self._deep_memory_profile_save and
self._deep_tempdir):
pyauto_utils.RemovePath(self._deep_tempdir)
+ # Must be done after perf.BasePerfTest.tearDown()
+ self._StopReplayServerIfNecessary()
+
+ def _GenArchiveName(self):
+ """Returns the Web Page Replay archive name that corresponds to a test.
+
+ Use test class name as archive name, e.g. ChromeEndureGmailTest.wpr,
Nirnimesh 2012/08/06 21:36:45 While this is nifty to auto-generate the archive n
fdeng1 2012/08/07 02:56:56 As discussed offline, I override _GetArchiveName i
+ which means we only have 1 archive file per test class.
+ Override this function to allow other names.
+
+ Returns:
+ An archive name generated using test class name.
+ """
+ # Use class name as archive name.
+ return self.id().split('.')[1] + '.wpr'
def _GetDeepMemoryProfileEnv(self, env_name, converter, default):
"""Returns a converted environment variable for the Deep Memory Profiler.
@@ -180,7 +218,9 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
extra_flags = ['--remote-debugging-port=9222']
if deep_memory_profile:
extra_flags.append('--no-sandbox')
- return (perf.BasePerfTest.ExtraChromeFlags(self) + extra_flags)
+ if self._use_wpr:
+ extra_flags.extend(ChromeEndureReplay.CHROME_FLAGS)
+ return perf.BasePerfTest.ExtraChromeFlags(self) + extra_flags
def _OnTimelineEvent(self, event_info):
"""Invoked by the Remote Inspector Client when a timeline event occurs.
@@ -540,6 +580,30 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
return True
+ def _StartReplayServerIfNecessary(self):
+ """Start replay server if necessary.
+
+ This method needs to be called BEFORE any connection (which is supposed
+ to go through the Web Page Replay server) occurs.
+ """
+ if self._use_wpr and not self._is_record_mode:
+ archive_name = self._GenArchiveName()
+ self._wpr_server = ChromeEndureReplay.ReplayServer(archive_name)
+ self._wpr_server.StartServer()
+ logging.info('Web Page Replay server has started in Replay mode.')
+
+ def _StopReplayServerIfNecessary(self):
+ """Stop the Web Page Replay server if necessary.
+
+ This method has to be called AFTER all network connections which go
+ through Web Page Replay server have shut down. Otherwise the
+ Web Page Replay server will hang to wait for them. A good
+ place is to call it at the end of the teardown process.
+ """
+ if self._use_wpr and not self._is_record_mode:
+ self._wpr_server.StopServer()
+ logging.info('The Web Page Replay server stopped.')
+
class ChromeEndureControlTest(ChromeEndureBaseTest):
"""Control tests for Chrome Endure."""
@@ -1123,5 +1187,33 @@ class IndexedDBOfflineTest(ChromeEndureBaseTest):
test_description, scenario)
+class ChromeEndureReplay(object):
+ """Run Chrome Endure tests with network simulation via Web Page Replay."""
+
+ _PATHS = {
+ 'archive':
+ 'src/chrome/test/data/pyauto_private/webpagereplay/{archive_name}',
+ 'scripts':
+ 'src/chrome/test/data/chrome_endure/webpagereplay/wpr_deterministic.js',
+ }
+ CHROME_FLAGS = webpagereplay.CHROME_FLAGS
+
+ @classmethod
+ def Path(cls, key, **kwargs):
+ return perf.FormatChromePath(cls._PATHS[key], **kwargs)
+
+ @classmethod
+ def ReplayServer(cls, archive_name):
+ """Creat a replay server."""
+ # Inject customized scripts for Google webapps.
+ # See the java script file for details.
Nirnimesh 2012/08/06 21:36:45 java script -> javascript
fdeng1 2012/08/07 02:56:56 Done.
+ scripts = cls.Path('scripts')
+ if not os.path.exists(scripts):
+ raise webpagereplay.ReplayNotFoundError('injected scripts', scripts)
+ replay_options = ['--inject_scripts', scripts]
+ archive_path = cls.Path('archive', archive_name=archive_name)
+ return webpagereplay.ReplayServer(archive_path, replay_options)
+
+
if __name__ == '__main__':
pyauto_functional.Main()

Powered by Google App Engine
This is Rietveld 408576698