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

Unified Diff: telemetry/telemetry/internal/actions/action_runner_unittest.py

Issue 2123713005: [Telemetry] Add MeasureMemory method to action_runner (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: added tests (+nits) Created 4 years, 5 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
« no previous file with comments | « telemetry/telemetry/internal/actions/action_runner.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/actions/action_runner_unittest.py
diff --git a/telemetry/telemetry/internal/actions/action_runner_unittest.py b/telemetry/telemetry/internal/actions/action_runner_unittest.py
index a708e0efba999f2e9d5cfe5cf5a52f99b001433f..902d12c4a716824e2b7d4e9bc1e77c28d5d0ca48 100644
--- a/telemetry/telemetry/internal/actions/action_runner_unittest.py
+++ b/telemetry/telemetry/internal/actions/action_runner_unittest.py
@@ -1,6 +1,7 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import mock
import unittest
from telemetry.core import exceptions
@@ -8,7 +9,7 @@ from telemetry import decorators
from telemetry.internal.actions import action_runner as action_runner_module
from telemetry.internal.actions import page_action
from telemetry.testing import tab_test_case
-import mock
+from telemetry.timeline import chrome_trace_category_filter
from telemetry.timeline import model
from telemetry.timeline import tracing_config
from telemetry.web_perf import timeline_interaction_record as tir_module
@@ -55,6 +56,47 @@ class ActionRunnerInteractionTest(tab_test_case.TabTestCase):
self.VerifyIssuingInteractionRecords(repeatable=True)
+class ActionRunnerMeasureMemoryTest(tab_test_case.TabTestCase):
+ def setUp(self):
+ super(ActionRunnerMeasureMemoryTest, self).setUp()
+ self.action_runner = action_runner_module.ActionRunner(self._tab,
+ skip_waits=True)
+ self.Navigate('blank.html')
+
+ def testWithoutTracing(self):
+ with mock.patch.object(self._tab.browser, 'DumpMemory') as mock_method:
nednguyen 2016/07/08 11:15:00 Can we not use mock here but instead assert the ex
perezju 2016/07/08 11:25:44 Note that I'm only using mock to assert that *some
nednguyen 2016/07/08 11:30:37 Oh I see. Sorry for not looking at this carefully
+ self.action_runner.MeasureMemory()
+ self.assertFalse(mock_method.called) # No-op with no tracing.
+
+ def _testWithTracing(self, deterministic_mode=False):
+ trace_memory = chrome_trace_category_filter.ChromeTraceCategoryFilter(
+ filter_string='-*,blink.console,disabled-by-default-memory-infra')
+ config = tracing_config.TracingConfig()
+ config.enable_chrome_trace = True
+ config.chrome_trace_config.SetCategoryFilter(trace_memory)
+ self._browser.platform.tracing_controller.StartTracing(config)
+ try:
+ self.action_runner.MeasureMemory(deterministic_mode)
+ finally:
+ self._browser.platform.tracing_controller.StopTracing()
+
+ def testDeterministicMode(self):
+ # Does not raise exception if dump is successful.
+ self._testWithTracing(deterministic_mode=True)
+
+ def testRealisticMode(self):
+ with mock.patch.object(
+ self.action_runner, 'ForceGarbageCollection') as mock_method:
+ self._testWithTracing(deterministic_mode=False)
+ self.assertFalse(mock_method.called) # No forced GC in "realistic" mode.
+
+ def testWithFailedDump(self):
+ with mock.patch.object(self._tab.browser, 'DumpMemory') as mock_method:
+ mock_method.return_value = False # Dump fails!
+ with self.assertRaises(AssertionError):
+ self._testWithTracing()
+
+
class ActionRunnerTest(tab_test_case.TabTestCase):
def testExecuteJavaScript(self):
action_runner = action_runner_module.ActionRunner(self._tab,
« no previous file with comments | « telemetry/telemetry/internal/actions/action_runner.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698