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

Unified Diff: telemetry/telemetry/internal/story_runner_unittest.py

Issue 2749633004: Track telemetry benchmark cycle time (Closed)
Patch Set: Fix tests Created 3 years, 9 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/story_runner.py ('k') | telemetry/telemetry/testing/fakes/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/story_runner_unittest.py
diff --git a/telemetry/telemetry/internal/story_runner_unittest.py b/telemetry/telemetry/internal/story_runner_unittest.py
index 44523ba48abb358485fab1cc44991aecbd2abc5b..1589c1dc1f2ce2dac175d55d93781bf7bbeda99c 100644
--- a/telemetry/telemetry/internal/story_runner_unittest.py
+++ b/telemetry/telemetry/internal/story_runner_unittest.py
@@ -2,15 +2,19 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
import math
import os
+import shutil
import StringIO
import sys
+import tempfile
import unittest
from py_utils import cloud_storage # pylint: disable=import-error
from telemetry import benchmark
+from telemetry import page
from telemetry.core import exceptions
from telemetry.core import util
from telemetry import decorators
@@ -22,6 +26,7 @@ from telemetry.internal.util import exception_formatter as ex_formatter_module
from telemetry.page import page as page_module
from telemetry.page import legacy_page_test
from telemetry import story as story_module
+from telemetry.testing import fakes
from telemetry.testing import options_for_unittests
from telemetry.testing import system_stub
import mock
@@ -40,7 +45,6 @@ from telemetry.wpr import archive_info
# pylint: disable=too-many-lines
-
class FakePlatform(object):
def CanMonitorThermalThrottling(self):
return False
@@ -54,7 +58,6 @@ class FakePlatform(object):
def GetDeviceTypeName(self):
return "GetDeviceTypeName"
-
class TestSharedState(story_module.SharedState):
_platform = FakePlatform()
@@ -151,6 +154,21 @@ def SetupStorySet(allow_multiple_story_states, story_state_list):
name='story%d' % i))
return story_set
+class FakeBenchmark(benchmark.Benchmark):
+ @classmethod
+ def Name(cls):
+ return 'fake'
+
+ test = DummyTest
+
+ def page_set(self):
+ story_set = story_module.StorySet()
+
+ example_page = page.Page(
+ 'https://www.example.com',
+ startup_url='https://www.example.com', page_set=story_set)
+ return story_set
+
def _GetOptionForUnittest():
options = options_for_unittests.GetCopy()
@@ -1036,3 +1054,36 @@ class StoryRunnerTest(unittest.TestCase):
mock.call.state.DidRunStory(root_mock.results),
mock.call.test.DidRunStory(root_mock.state.platform)
])
+
+ def testRunBenchmarkTimeDuration(self):
+ fake_benchmark = FakeBenchmark()
+ options = fakes._FakeBrowserFinderOptions()
nednguyen 2017/03/23 23:26:52 Use options = fakes.CreateBrowserFinderOptions() i
martiniss 2017/03/24 17:28:36 Done.
+ options.upload_results = None
+ options.suppress_gtest_report = False
+ options.results_label = None
+ options.use_live_sites = False
+ options.max_failures = 100
+ options.pageset_repeat = 1
+ options.output_formats = ['chartjson']
+
+ with mock.patch('telemetry.internal.story_runner.time.time') as time_patch:
+ # 3, because telemetry code asks for the time at some point
+ time_patch.side_effect = [1, 0, 61]
+ tmp_path = tempfile.mkdtemp()
+
+ try:
+ options.output_dir = tmp_path
+ story_runner.RunBenchmark(fake_benchmark, options)
+ with open(os.path.join(tmp_path, 'results-chart.json')) as f:
+ data = json.load(f)
+
+ self.assertEqual(len(data['charts']), 1)
+ charts = data['charts']
+ self.assertIn('BenchmarkDuration', charts)
+ duration = charts['BenchmarkDuration']
+ self.assertIn("summary", duration)
+ summary = duration['summary']
+ duration = summary['value']
+ self.assertTrue(abs(duration - 1) < 0.001)
nednguyen 2017/03/23 23:26:52 nits: self.assertAlmostEqual(duration, 1)
martiniss 2017/03/24 17:28:36 Done.
+ finally:
+ shutil.rmtree(tmp_path)
« no previous file with comments | « telemetry/telemetry/internal/story_runner.py ('k') | telemetry/telemetry/testing/fakes/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698