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

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

Issue 3000303002: [pinpoint] Support multiple Swarming tasks. (Closed)
Patch Set: Created 3 years, 4 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 @mock.patch('dashboard.services.isolate_service.Retrieve') 13 @mock.patch('dashboard.services.isolate_service.Retrieve')
14 class ReadChartJsonValueTest(unittest.TestCase): 14 class ReadChartJsonValueTest(unittest.TestCase):
15 15
16 def testReadChartJsonValue(self, retrieve): 16 def testReadChartJsonValue(self, retrieve):
17 retrieve.side_effect = ( 17 retrieve.side_effect = (
18 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 18 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
19 json.dumps({'charts': {'metric': {'test': { 19 json.dumps({'charts': {'metric': {'test': {
20 'type': 'list_of_scalar_values', 20 'type': 'list_of_scalar_values',
21 'values': [0, 1, 2], 21 'values': [0, 1, 2],
22 }}}}), 22 }}}}),
23 ) 23 )
24 24
25 quest = read_value.ReadChartJsonValue('metric', 'test') 25 quest = read_value.ReadChartJsonValue('metric', 'test')
26 execution = quest.Start('output hash') 26 execution = quest.Start(('output hash',))
27 execution.Poll() 27 execution.Poll()
28 28
29 self.assertTrue(execution.completed) 29 self.assertTrue(execution.completed)
30 self.assertFalse(execution.failed) 30 self.assertFalse(execution.failed)
31 self.assertEqual(execution.result_values, (0, 1, 2)) 31 self.assertEqual(execution.result_values, (0, 1, 2))
32 self.assertEqual(execution.result_arguments, {}) 32 self.assertEqual(execution.result_arguments, {})
33 33
34 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')] 34 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')]
35 self.assertEqual(retrieve.mock_calls, expected_calls) 35 self.assertEqual(retrieve.mock_calls, expected_calls)
36 36
37 def testReadChartJsonValueWithNoTest(self, retrieve): 37 def testReadChartJsonValueWithNoTest(self, retrieve):
38 retrieve.side_effect = ( 38 retrieve.side_effect = (
39 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 39 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
40 json.dumps({'charts': {'metric': {'summary': { 40 json.dumps({'charts': {'metric': {'summary': {
41 'type': 'list_of_scalar_values', 41 'type': 'list_of_scalar_values',
42 'values': [0, 1, 2], 42 'values': [0, 1, 2],
43 }}}}), 43 }}}}),
44 ) 44 )
45 45
46 quest = read_value.ReadChartJsonValue('metric', None) 46 quest = read_value.ReadChartJsonValue('metric', None)
47 execution = quest.Start('output hash') 47 execution = quest.Start(('output hash',))
48 execution.Poll() 48 execution.Poll()
49 49
50 self.assertTrue(execution.completed) 50 self.assertTrue(execution.completed)
51 self.assertFalse(execution.failed) 51 self.assertFalse(execution.failed)
52 self.assertEqual(execution.result_values, (0, 1, 2)) 52 self.assertEqual(execution.result_values, (0, 1, 2))
53 self.assertEqual(execution.result_arguments, {}) 53 self.assertEqual(execution.result_arguments, {})
54 54
55 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')] 55 expected_calls = [mock.call('output hash'), mock.call('chartjson hash')]
56 self.assertEqual(retrieve.mock_calls, expected_calls) 56 self.assertEqual(retrieve.mock_calls, expected_calls)
57 57
58 def testHistogram(self, retrieve): 58 def testHistogram(self, retrieve):
59 retrieve.side_effect = ( 59 retrieve.side_effect = (
60 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 60 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
61 json.dumps({'charts': {'metric': {'test': { 61 json.dumps({'charts': {'metric': {'test': {
62 'type': 'histogram', 62 'type': 'histogram',
63 'buckets': [ 63 'buckets': [
64 {'low': 0, 'count': 2}, 64 {'low': 0, 'count': 2},
65 {'low': 0, 'high': 2, 'count': 3}, 65 {'low': 0, 'high': 2, 'count': 3},
66 ], 66 ],
67 }}}}), 67 }}}}),
68 ) 68 )
69 69
70 quest = read_value.ReadChartJsonValue('metric', 'test') 70 quest = read_value.ReadChartJsonValue('metric', 'test')
71 execution = quest.Start('output hash') 71 execution = quest.Start(('output hash',))
72 execution.Poll() 72 execution.Poll()
73 73
74 self.assertEqual(execution.result_values, (0, 0, 1, 1, 1)) 74 self.assertEqual(execution.result_values, (0, 0, 1, 1, 1))
75 75
76 def testHistogramWithLargeSample(self, retrieve): 76 def testHistogramWithLargeSample(self, retrieve):
77 retrieve.side_effect = ( 77 retrieve.side_effect = (
78 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 78 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
79 json.dumps({'charts': {'metric': {'test': { 79 json.dumps({'charts': {'metric': {'test': {
80 'type': 'histogram', 80 'type': 'histogram',
81 'buckets': [ 81 'buckets': [
82 {'low': 0, 'count': 20000}, 82 {'low': 0, 'count': 20000},
83 {'low': 0, 'high': 2, 'count': 30000}, 83 {'low': 0, 'high': 2, 'count': 30000},
84 ], 84 ],
85 }}}}), 85 }}}}),
86 ) 86 )
87 87
88 quest = read_value.ReadChartJsonValue('metric', 'test') 88 quest = read_value.ReadChartJsonValue('metric', 'test')
89 execution = quest.Start('output hash') 89 execution = quest.Start(('output hash',))
90 execution.Poll() 90 execution.Poll()
91 91
92 self.assertEqual(execution.result_values, tuple([0] * 4000 + [1] * 6000)) 92 self.assertEqual(execution.result_values, tuple([0] * 4000 + [1] * 6000))
93 93
94 def testScalar(self, retrieve): 94 def testScalar(self, retrieve):
95 retrieve.side_effect = ( 95 retrieve.side_effect = (
96 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}}, 96 {'files': {'chartjson-output.json': {'h': 'chartjson hash'}}},
97 json.dumps({'charts': {'metric': {'test': { 97 json.dumps({'charts': {'metric': {'test': {
98 'type': 'scalar', 98 'type': 'scalar',
99 'value': 2.5, 99 'value': 2.5,
100 }}}}), 100 }}}}),
101 ) 101 )
102 102
103 quest = read_value.ReadChartJsonValue('metric', 'test') 103 quest = read_value.ReadChartJsonValue('metric', 'test')
104 execution = quest.Start('output hash') 104 execution = quest.Start(('output hash',))
105 execution.Poll() 105 execution.Poll()
106 106
107 self.assertEqual(execution.result_values, (2.5,)) 107 self.assertEqual(execution.result_values, (2.5,))
108 108
109 109
110 @mock.patch('dashboard.services.isolate_service.Retrieve') 110 @mock.patch('dashboard.services.isolate_service.Retrieve')
111 class ReadGraphJsonValueTest(unittest.TestCase): 111 class ReadGraphJsonValueTest(unittest.TestCase):
112 112
113 def testReadGraphJsonValue(self, retrieve): 113 def testReadGraphJsonValue(self, retrieve):
114 retrieve.side_effect = ( 114 retrieve.side_effect = (
115 {'files': {'chartjson-output.json': {'h': 'graphjson hash'}}}, 115 {'files': {'chartjson-output.json': {'h': 'graphjson hash'}}},
116 json.dumps({'chart': {'traces': {'trace': ['126444.869721', '0.0']}}}), 116 json.dumps({'chart': {'traces': {'trace': ['126444.869721', '0.0']}}}),
117 ) 117 )
118 118
119 quest = read_value.ReadGraphJsonValue('chart', 'trace') 119 quest = read_value.ReadGraphJsonValue('chart', 'trace')
120 execution = quest.Start('output hash') 120 execution = quest.Start(('output hash',))
121 execution.Poll() 121 execution.Poll()
122 122
123 self.assertTrue(execution.completed) 123 self.assertTrue(execution.completed)
124 self.assertFalse(execution.failed) 124 self.assertFalse(execution.failed)
125 self.assertEqual(execution.result_values, (126444.869721,)) 125 self.assertEqual(execution.result_values, (126444.869721,))
126 self.assertEqual(execution.result_arguments, {}) 126 self.assertEqual(execution.result_arguments, {})
127 127
128 expected_calls = [mock.call('output hash'), mock.call('graphjson hash')] 128 expected_calls = [mock.call('output hash'), mock.call('graphjson hash')]
129 self.assertEqual(retrieve.mock_calls, expected_calls) 129 self.assertEqual(retrieve.mock_calls, expected_calls)
OLDNEW
« no previous file with comments | « dashboard/dashboard/pinpoint/models/quest/read_value.py ('k') | dashboard/dashboard/pinpoint/models/quest/run_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698