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

Unified Diff: tools/perf/measurements/smoothness_unittest.py

Issue 409113006: Don't rely only on __del__ to cleanup PowerMetric when Smoothness.DidRunActions is not called. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make unit tests nicer! Created 6 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 | « tools/perf/measurements/smoothness.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/measurements/smoothness_unittest.py
diff --git a/tools/perf/measurements/smoothness_unittest.py b/tools/perf/measurements/smoothness_unittest.py
index e537399237661481f02e767b04604c9ba982a614..e82634241325ec4bd6e7c8c63cf203525f47e6af 100644
--- a/tools/perf/measurements/smoothness_unittest.py
+++ b/tools/perf/measurements/smoothness_unittest.py
@@ -4,9 +4,12 @@
import sys
from measurements import smoothness
+from metrics import power
+from telemetry.core import exceptions
from telemetry.core import wpr_modes
from telemetry.page import page
from telemetry.page import page_measurement_unittest_base
+from telemetry.page import page_test
from telemetry.unittest import options_for_unittests
class FakePlatform(object):
@@ -131,3 +134,38 @@ class SmoothnessUnitTest(
def testCleanUpTrace(self):
self.TestTracingCleanedUp(smoothness.Smoothness, self._options)
+
+ def testCleanUpPowerMetric(self):
+ class FailPage(page.Page):
+ def __init__(self, page_set):
+ super(FailPage, self).__init__(
+ url='file://blank.html',
+ page_set=page_set, base_dir=page_set.base_dir)
+ def RunSmoothness(self, _):
+ raise exceptions.IntentionalException
+
+ class FakePowerMetric(power.PowerMetric):
+ start_called = False
+ stop_called = True
+ def Start(self, _1, _2):
+ self.start_called = True
+ def Stop(self, _1, _2):
+ self.stop_called = True
+
+ ps = self.CreateEmptyPageSet()
+ ps.AddPage(FailPage(ps))
+
+ class BuggyMeasurement(smoothness.Smoothness):
+ fake_power = None
+ # Inject fake power metric.
+ def WillStartBrowser(self, browser):
+ self.fake_power = self._power_metric = FakePowerMetric(browser)
+
+ measurement = BuggyMeasurement()
+ try:
+ self.RunMeasurement(measurement, ps)
+ except page_test.TestNotSupportedOnPlatformFailure:
+ pass
+
+ self.assertTrue(measurement.fake_power.start_called)
+ self.assertTrue(measurement.fake_power.stop_called)
« no previous file with comments | « tools/perf/measurements/smoothness.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698