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

Side by Side Diff: dashboard/dashboard/pinpoint/models/quest/read_value_test.py

Issue 3014663002: [pinpoint] Add trace links.
Patch Set: Created 3 years, 2 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 unified diff | Download patch
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import unittest 6 import unittest
7 7
8 import mock 8 import mock
9 9
10 from dashboard.pinpoint.models.quest import read_value 10 from dashboard.pinpoint.models.quest import read_value
11 11
12 12
13 class _ReadValueTest(unittest.TestCase): 13 class _ReadValueTest(unittest.TestCase):
14 14
15 def assertReadValueError(self, execution): 15 def assertReadValueError(self, execution):
16 self.assertTrue(execution.completed) 16 self.assertTrue(execution.completed)
17 self.assertTrue(execution.failed) 17 self.assertTrue(execution.failed)
18 self.assertIsInstance(execution.exception, basestring) 18 self.assertIsInstance(execution.exception, basestring)
19 last_exception_line = execution.exception.splitlines()[-1] 19 last_exception_line = execution.exception.splitlines()[-1]
20 self.assertTrue(last_exception_line.startswith('ReadValueError')) 20 self.assertTrue(last_exception_line.startswith('ReadValueError'))
21 21
22 22
23 @mock.patch('dashboard.services.isolate_service.Retrieve') 23 @mock.patch('dashboard.services.isolate_service.Retrieve')
24 class ReadChartJsonValueTest(_ReadValueTest): 24 class ReadChartJsonValueTest(_ReadValueTest):
25 25
26 def testReadChartJsonValue(self, retrieve): 26 def testReadChartJsonValue(self, retrieve):
27 retrieve.side_effect = ( 27 retrieve.side_effect = (
28 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 28 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
29 json.dumps({'charts': {'tir_label@@chart': {'trace': { 29 json.dumps({'charts': {
30 'type': 'list_of_scalar_values', 30 'tir_label@@chart': {'trace name': {
31 'values': [0, 1, 2], 31 'type': 'list_of_scalar_values',
32 }}}}), 32 'values': [0, 1, 2],
33 }},
34 'trace': {'trace name': {'cloud_url': 'trace url'}},
35 }}),
33 ) 36 )
34 37
35 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace') 38 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace name')
36 execution = quest.Start(None, 'output hash') 39 execution = quest.Start(None, 'output hash')
37 execution.Poll() 40 execution.Poll()
38 41
39 self.assertTrue(execution.completed) 42 self.assertTrue(execution.completed)
40 self.assertFalse(execution.failed) 43 self.assertFalse(execution.failed)
41 self.assertEqual(execution.result_values, (0, 1, 2)) 44 self.assertEqual(execution.result_values, (0, 1, 2))
42 self.assertEqual(execution.result_arguments, {}) 45 self.assertEqual(execution.result_arguments, {})
43 46
44 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')] 47 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')]
45 self.assertEqual(retrieve.mock_calls, expected_calls) 48 self.assertEqual(retrieve.mock_calls, expected_calls)
46 49
47 def testReadChartJsonValueWithNoTirLabel(self, retrieve): 50 def testReadChartJsonValueWithNoTirLabel(self, retrieve):
48 retrieve.side_effect = ( 51 retrieve.side_effect = (
49 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 52 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
50 json.dumps({'charts': {'chart': {'trace': { 53 json.dumps({'charts': {
51 'type': 'list_of_scalar_values', 54 'chart': {'trace name': {
52 'values': [0, 1, 2], 55 'type': 'list_of_scalar_values',
53 }}}}), 56 'values': [0, 1, 2],
57 }},
58 'trace': {'trace name': {'cloud_url': 'trace url'}},
59 }}),
54 ) 60 )
55 61
56 quest = read_value.ReadChartJsonValue('chart', None, 'trace') 62 quest = read_value.ReadChartJsonValue('chart', None, 'trace name')
57 execution = quest.Start(None, 'output hash') 63 execution = quest.Start(None, 'output hash')
58 execution.Poll() 64 execution.Poll()
59 65
60 self.assertTrue(execution.completed) 66 self.assertTrue(execution.completed)
61 self.assertFalse(execution.failed) 67 self.assertFalse(execution.failed)
62 self.assertEqual(execution.result_values, (0, 1, 2)) 68 self.assertEqual(execution.result_values, (0, 1, 2))
63 self.assertEqual(execution.result_arguments, {}) 69 self.assertEqual(execution.result_arguments, {})
64 70
65 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')] 71 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')]
66 self.assertEqual(retrieve.mock_calls, expected_calls) 72 self.assertEqual(retrieve.mock_calls, expected_calls)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 self.assertFalse(execution.failed) 121 self.assertFalse(execution.failed)
116 self.assertEqual(execution.result_values, (0, 1, 2)) 122 self.assertEqual(execution.result_values, (0, 1, 2))
117 self.assertEqual(execution.result_arguments, {}) 123 self.assertEqual(execution.result_arguments, {})
118 124
119 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')] 125 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')]
120 self.assertEqual(retrieve.mock_calls, expected_calls) 126 self.assertEqual(retrieve.mock_calls, expected_calls)
121 127
122 def testHistogram(self, retrieve): 128 def testHistogram(self, retrieve):
123 retrieve.side_effect = ( 129 retrieve.side_effect = (
124 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 130 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
125 json.dumps({'charts': {'tir_label@@chart': {'trace': { 131 json.dumps({'charts': {
126 'type': 'histogram', 132 'tir_label@@chart': {'trace name': {
127 'buckets': [ 133 'type': 'histogram',
128 {'low': 0, 'count': 2}, 134 'buckets': [
129 {'low': 0, 'high': 2, 'count': 3}, 135 {'low': 0, 'count': 2},
130 ], 136 {'low': 0, 'high': 2, 'count': 3},
131 }}}}), 137 ],
138 }},
139 'trace': {'trace name': {'cloud_url': 'trace url'}},
140 }}),
132 ) 141 )
133 142
134 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace') 143 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace name')
135 execution = quest.Start(None, 'output hash') 144 execution = quest.Start(None, 'output hash')
136 execution.Poll() 145 execution.Poll()
137 146
138 self.assertEqual(execution.result_values, (0, 0, 1, 1, 1)) 147 self.assertEqual(execution.result_values, (0, 0, 1, 1, 1))
139 148
140 def testHistogramWithLargeSample(self, retrieve): 149 def testHistogramWithLargeSample(self, retrieve):
141 retrieve.side_effect = ( 150 retrieve.side_effect = (
142 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 151 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
143 json.dumps({'charts': {'tir_label@@chart': {'trace': { 152 json.dumps({'charts': {
144 'type': 'histogram', 153 'tir_label@@chart': {'trace name': {
145 'buckets': [ 154 'type': 'histogram',
146 {'low': 0, 'count': 20000}, 155 'buckets': [
147 {'low': 0, 'high': 2, 'count': 30000}, 156 {'low': 0, 'count': 20000},
148 ], 157 {'low': 0, 'high': 2, 'count': 30000},
149 }}}}), 158 ],
159 }},
160 'trace': {'trace name': {'cloud_url': 'trace url'}},
161 }}),
150 ) 162 )
151 163
152 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace') 164 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace name')
153 execution = quest.Start(None, 'output hash') 165 execution = quest.Start(None, 'output hash')
154 execution.Poll() 166 execution.Poll()
155 167
156 self.assertEqual(execution.result_values, tuple([0] * 4000 + [1] * 6000)) 168 self.assertEqual(execution.result_values, tuple([0] * 4000 + [1] * 6000))
157 169
158 def testScalar(self, retrieve): 170 def testScalar(self, retrieve):
159 retrieve.side_effect = ( 171 retrieve.side_effect = (
160 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 172 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
161 json.dumps({'charts': {'tir_label@@chart': {'trace': { 173 json.dumps({'charts': {
162 'type': 'scalar', 174 'tir_label@@chart': {'trace name': {
163 'value': 2.5, 175 'type': 'scalar',
164 }}}}), 176 'value': 2.5,
177 }},
178 'trace': {'trace name': {'cloud_url': 'trace url'}},
179 }}),
165 ) 180 )
166 181
167 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace') 182 quest = read_value.ReadChartJsonValue('chart', 'tir_label', 'trace name')
168 execution = quest.Start(None, 'output hash') 183 execution = quest.Start(None, 'output hash')
169 execution.Poll() 184 execution.Poll()
170 185
171 self.assertEqual(execution.result_values, (2.5,)) 186 self.assertEqual(execution.result_values, (2.5,))
172 187
173 188
174 @mock.patch('dashboard.services.isolate_service.Retrieve') 189 @mock.patch('dashboard.services.isolate_service.Retrieve')
175 class ReadGraphJsonValueTest(_ReadValueTest): 190 class ReadGraphJsonValueTest(_ReadValueTest):
176 191
177 def testReadGraphJsonValue(self, retrieve): 192 def testReadGraphJsonValue(self, retrieve):
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 retrieve.side_effect = ( 232 retrieve.side_effect = (
218 {'files': {'chartjson-output.json': {'h': 'graphjson hash'}}}, 233 {'files': {'chartjson-output.json': {'h': 'graphjson hash'}}},
219 json.dumps({'chart': {'traces': {}}}), 234 json.dumps({'chart': {'traces': {}}}),
220 ) 235 )
221 236
222 quest = read_value.ReadGraphJsonValue('metric', 'test') 237 quest = read_value.ReadGraphJsonValue('metric', 'test')
223 execution = quest.Start(None, 'output hash') 238 execution = quest.Start(None, 'output hash')
224 execution.Poll() 239 execution.Poll()
225 240
226 self.assertReadValueError(execution) 241 self.assertReadValueError(execution)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698