Commit e840c3fc authored by chrishenry@google.com's avatar chrishenry@google.com

Don't rely only on __del__ to cleanup PowerMetric when Smoothness.DidRunActions is not called.

Now, CleanUpAfterPage will also do the cleanup. (This is not a great
solution, but it will unblock the other patch without re-engineering
the whole resource cleanup mechanisms.)

In my other patch, the order of GC changes somehow (not sure yet why),
which caused SmoothnessUnitTest to fail since __del__ is not called
before the next test starts.

BUG=350841,348271

Review URL: https://codereview.chromium.org/409113006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284868 0039d316-1c4b-4281-b951-d872f2087c98
parent 903df2b5
......@@ -35,5 +35,8 @@ class Smoothness(page_measurement.PageMeasurement):
self._power_metric.AddResults(tab, results)
self._smoothness_controller.AddResults(tab, results)
def CleanUpAfterPage(self, _, tab):
self._smoothness_controller.CleanUp(tab)
def CleanUpAfterPage(self, page, tab):
if self._power_metric:
self._power_metric.Stop(page, tab)
if self._smoothness_controller:
self._smoothness_controller.CleanUp(tab)
......@@ -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)
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