| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 os | 5 import os |
| 6 import string | 6 import string |
| 7 import sys | 7 import sys |
| 8 import tempfile | 8 import tempfile |
| 9 import unittest | 9 import unittest |
| 10 import json | 10 import json |
| 11 | 11 |
| 12 import mock |
| 13 |
| 14 from telemetry import decorators |
| 12 from telemetry import project_config | 15 from telemetry import project_config |
| 13 from telemetry.core import util | 16 from telemetry.core import util |
| 14 from telemetry.testing import browser_test_context | |
| 15 from telemetry.testing import browser_test_runner | 17 from telemetry.testing import browser_test_runner |
| 16 from telemetry.testing import options_for_unittests | |
| 17 from telemetry.testing import run_browser_tests | |
| 18 from telemetry.testing import serially_executed_browser_test_case | 18 from telemetry.testing import serially_executed_browser_test_case |
| 19 | 19 |
| 20 | 20 |
| 21 class BrowserTestRunnerTest(unittest.TestCase): | 21 class BrowserTestRunnerTest(unittest.TestCase): |
| 22 | 22 |
| 23 def _ExtractTestResults(self, test_result): | 23 def baseTest(self, mockInitDependencyManager, test_filter, |
| 24 delimiter = test_result['path_delimiter'] | |
| 25 failures = [] | |
| 26 successes = [] | |
| 27 def _IsLeafNode(node): | |
| 28 test_dict = node[1] | |
| 29 return ('expected' in test_dict and | |
| 30 isinstance(test_dict['expected'], basestring)) | |
| 31 node_queues = [] | |
| 32 for t in test_result['tests']: | |
| 33 node_queues.append((t, test_result['tests'][t])) | |
| 34 while node_queues: | |
| 35 node = node_queues.pop() | |
| 36 full_test_name, test_dict = node | |
| 37 if _IsLeafNode(node): | |
| 38 if all(res not in test_dict['expected'].split() for res in | |
| 39 test_dict['actual'].split()): | |
| 40 failures.append(full_test_name) | |
| 41 else: | |
| 42 successes.append(full_test_name) | |
| 43 else: | |
| 44 for k in test_dict: | |
| 45 node_queues.append( | |
| 46 ('%s%s%s' % (full_test_name, delimiter, k), | |
| 47 test_dict[k])) | |
| 48 return successes, failures | |
| 49 | |
| 50 def baseTest(self, test_filter, | |
| 51 failures, successes, test_name='SimpleTest'): | 24 failures, successes, test_name='SimpleTest'): |
| 25 options = browser_test_runner.TestRunOptions() |
| 26 options.verbosity = 0 |
| 52 config = project_config.ProjectConfig( | 27 config = project_config.ProjectConfig( |
| 53 top_level_dir=os.path.join(util.GetTelemetryDir(), 'examples'), | 28 top_level_dir=os.path.join(util.GetTelemetryDir(), 'examples'), |
| 54 client_configs=[], | 29 client_configs=['a', 'b', 'c'], |
| 55 benchmark_dirs=[ | 30 benchmark_dirs=[ |
| 56 os.path.join(util.GetTelemetryDir(), 'examples', 'browser_tests')] | 31 os.path.join(util.GetTelemetryDir(), 'examples', 'browser_tests')] |
| 57 ) | 32 ) |
| 58 temp_file = tempfile.NamedTemporaryFile(delete=False) | 33 temp_file = tempfile.NamedTemporaryFile(delete=False) |
| 59 temp_file.close() | 34 temp_file.close() |
| 60 temp_file_name = temp_file.name | 35 temp_file_name = temp_file.name |
| 61 try: | 36 try: |
| 62 browser_test_runner.Run( | 37 browser_test_runner.Run( |
| 63 config, | 38 config, options, |
| 64 [test_name, | 39 [test_name, |
| 65 '--write-full-results-to=%s' % temp_file_name, | 40 '--write-abbreviated-json-results-to=%s' % temp_file_name, |
| 66 '--test-filter=%s' % test_filter]) | 41 '--test-filter=%s' % test_filter]) |
| 42 mockInitDependencyManager.assert_called_with(['a', 'b', 'c']) |
| 67 with open(temp_file_name) as f: | 43 with open(temp_file_name) as f: |
| 68 test_result = json.load(f) | 44 test_result = json.load(f) |
| 69 | 45 self.assertEquals(test_result['failures'], failures) |
| 70 actual_successes, actual_failures = self._ExtractTestResults(test_result) | 46 self.assertEquals(test_result['successes'], successes) |
| 71 self.assertEquals(set(actual_failures), set(failures)) | 47 self.assertEquals(test_result['valid'], True) |
| 72 self.assertEquals(set(actual_successes), set(successes)) | |
| 73 finally: | 48 finally: |
| 74 os.remove(temp_file_name) | 49 os.remove(temp_file_name) |
| 75 | 50 |
| 76 def testJsonOutputFormatNegativeFilter(self): | 51 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 52 def testJsonOutputFormatNegativeFilter(self, mockInitDependencyManager): |
| 77 self.baseTest( | 53 self.baseTest( |
| 78 '^(add|multiplier).*', | 54 mockInitDependencyManager, '^(add|multiplier).*', |
| 79 ['browser_tests.simple_numeric_test.SimpleTest.add_1_and_2', | 55 ['add_1_and_2', |
| 80 'browser_tests.simple_numeric_test.SimpleTest.add_7_and_3', | 56 'add_7_and_3', |
| 81 'browser_tests.simple_numeric_test.SimpleTest.multiplier_simple_2'], | 57 'multiplier_simple_2'], |
| 82 ['browser_tests.simple_numeric_test.SimpleTest.add_2_and_3', | 58 ['add_2_and_3', |
| 83 'browser_tests.simple_numeric_test.SimpleTest.multiplier_simple', | 59 'multiplier_simple', |
| 84 'browser_tests.simple_numeric_test.SimpleTest.multiplier_simple_3']) | 60 'multiplier_simple_3']) |
| 85 | 61 |
| 86 def testJsonOutputWhenSetupClassFailed(self): | 62 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 63 def testJsonOutputWhenSetupClassFailed(self, mockInitDependencyManager): |
| 87 self.baseTest( | 64 self.baseTest( |
| 88 '.*', | 65 mockInitDependencyManager, '.*', |
| 89 ['browser_tests.failed_tests.SetUpClassFailedTest.dummy_test_0', | 66 ['setUpClass (browser_tests.failed_tests.SetUpClassFailedTest)'], |
| 90 'browser_tests.failed_tests.SetUpClassFailedTest.dummy_test_1', | |
| 91 'browser_tests.failed_tests.SetUpClassFailedTest.dummy_test_2'], | |
| 92 [], test_name='SetUpClassFailedTest') | 67 [], test_name='SetUpClassFailedTest') |
| 93 | 68 |
| 94 def testJsonOutputWhenTearDownClassFailed(self): | 69 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 70 def testJsonOutputWhenTearDownClassFailed(self, mockInitDependencyManager): |
| 95 self.baseTest( | 71 self.baseTest( |
| 96 '.*', | 72 mockInitDependencyManager, '.*', |
| 97 ['browser_tests.failed_tests.TearDownClassFailedTest.dummy_test_0', | 73 ['tearDownClass (browser_tests.failed_tests.TearDownClassFailedTest)'], |
| 98 'browser_tests.failed_tests.TearDownClassFailedTest.dummy_test_1', | 74 sorted(['dummy_test_%i' %i for i in xrange(0, 100)]), |
| 99 'browser_tests.failed_tests.TearDownClassFailedTest.dummy_test_2'], | 75 test_name='TearDownClassFailedTest') |
| 100 [], test_name='TearDownClassFailedTest') | |
| 101 | 76 |
| 102 def testSetUpProcessCalledOnce(self): | 77 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 78 def testJsonOutputFormatPositiveFilter(self, mockInitDependencyManager): |
| 103 self.baseTest( | 79 self.baseTest( |
| 104 '.*', | 80 mockInitDependencyManager, '(TestSimple|TestException).*', |
| 105 [], | 81 ['TestException', 'TestSimple'], []) |
| 106 ['browser_tests.process_tests.FailIfSetUpProcessCalledTwice.Dummy_0', | |
| 107 'browser_tests.process_tests.FailIfSetUpProcessCalledTwice.Dummy_1', | |
| 108 'browser_tests.process_tests.FailIfSetUpProcessCalledTwice.Dummy_2'], | |
| 109 test_name='FailIfSetUpProcessCalledTwice') | |
| 110 | 82 |
| 111 def testTearDownProcessCalledOnce(self): | 83 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 112 self.baseTest( | 84 def testExecutingTestsInSortedOrder(self, mockInitDependencyManager): |
| 113 '.*', | |
| 114 [], | |
| 115 ['browser_tests.process_tests.FailIfTearDownProcessCalledTwice.Dummy_0', | |
| 116 'browser_tests.process_tests.FailIfTearDownProcessCalledTwice.Dummy_1', | |
| 117 'browser_tests.process_tests.FailIfTearDownProcessCalledTwice.Dummy_2'], | |
| 118 test_name='FailIfTearDownProcessCalledTwice') | |
| 119 | |
| 120 def testJsonOutputFormatPositiveFilter(self): | |
| 121 self.baseTest( | |
| 122 '(TestSimple|TestException).*', | |
| 123 ['browser_tests.simple_numeric_test.SimpleTest.TestException', | |
| 124 'browser_tests.simple_numeric_test.SimpleTest.TestSimple'], []) | |
| 125 | |
| 126 def testExecutingTestsInSortedOrder(self): | |
| 127 alphabetical_tests = [] | 85 alphabetical_tests = [] |
| 128 prefix = 'browser_tests.simple_numeric_test.SimpleTest.Alphabetical_' | 86 prefix = 'Alphabetical_' |
| 129 for i in xrange(20): | 87 for i in xrange(20): |
| 130 alphabetical_tests.append(prefix + str(i)) | 88 alphabetical_tests.append(prefix + str(i)) |
| 131 for c in string.uppercase[:26]: | 89 for c in string.uppercase[:26]: |
| 132 alphabetical_tests.append(prefix + c) | 90 alphabetical_tests.append(prefix + c) |
| 133 for c in string.lowercase[:26]: | 91 for c in string.lowercase[:26]: |
| 134 alphabetical_tests.append(prefix + c) | 92 alphabetical_tests.append(prefix + c) |
| 135 alphabetical_tests.sort() | 93 alphabetical_tests.sort() |
| 136 self.baseTest( | 94 self.baseTest( |
| 137 'Alphabetical', [], alphabetical_tests) | 95 mockInitDependencyManager, 'Alphabetical', [], alphabetical_tests) |
| 138 | 96 |
| 139 def shardingRangeTestHelper(self, total_shards, num_tests): | 97 def shardingRangeTestHelper(self, total_shards, num_tests): |
| 140 shard_ranges = [] | 98 shard_ranges = [] |
| 141 for shard_index in xrange(0, total_shards): | 99 for shard_index in xrange(0, total_shards): |
| 142 shard_ranges.append(run_browser_tests._TestRangeForShard( | 100 shard_ranges.append(browser_test_runner._TestRangeForShard( |
| 143 total_shards, shard_index, num_tests)) | 101 total_shards, shard_index, num_tests)) |
| 144 # Make assertions about ranges | 102 # Make assertions about ranges |
| 145 num_tests_run = 0 | 103 num_tests_run = 0 |
| 146 for i in xrange(0, len(shard_ranges)): | 104 for i in xrange(0, len(shard_ranges)): |
| 147 cur_range = shard_ranges[i] | 105 cur_range = shard_ranges[i] |
| 148 if i < num_tests: | 106 if i < num_tests: |
| 149 self.assertGreater(cur_range[1], cur_range[0]) | 107 self.assertGreater(cur_range[1], cur_range[0]) |
| 150 num_tests_run += (cur_range[1] - cur_range[0]) | 108 num_tests_run += (cur_range[1] - cur_range[0]) |
| 151 else: | 109 else: |
| 152 # Not enough tests to go around all of the shards. | 110 # Not enough tests to go around all of the shards. |
| 153 self.assertEquals(cur_range[0], cur_range[1]) | 111 self.assertEquals(cur_range[0], cur_range[1]) |
| 154 # Make assertions about non-overlapping ranges | 112 # Make assertions about non-overlapping ranges |
| 155 for i in xrange(1, len(shard_ranges)): | 113 for i in xrange(1, len(shard_ranges)): |
| 156 prev_range = shard_ranges[i - 1] | 114 prev_range = shard_ranges[i - 1] |
| 157 cur_range = shard_ranges[i] | 115 cur_range = shard_ranges[i] |
| 158 self.assertEquals(prev_range[1], cur_range[0]) | 116 self.assertEquals(prev_range[1], cur_range[0]) |
| 159 # Assert that we run all of the tests (very important) | 117 # Assert that we run all of the tests (very important) |
| 160 self.assertEquals(num_tests_run, num_tests) | 118 self.assertEquals(num_tests_run, num_tests) |
| 161 | 119 |
| 162 def testShardsWithPrimeNumTests(self): | 120 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 121 def testShardsWithPrimeNumTests(self, _): |
| 163 for total_shards in xrange(1, 20): | 122 for total_shards in xrange(1, 20): |
| 164 # Nice non-prime number | 123 # Nice non-prime number |
| 165 self.shardingRangeTestHelper(total_shards, 101) | 124 self.shardingRangeTestHelper(total_shards, 101) |
| 166 | 125 |
| 167 def testShardsWithDivisibleNumTests(self): | 126 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 127 def testShardsWithDivisibleNumTests(self, _): |
| 168 for total_shards in xrange(1, 6): | 128 for total_shards in xrange(1, 6): |
| 169 self.shardingRangeTestHelper(total_shards, 8) | 129 self.shardingRangeTestHelper(total_shards, 8) |
| 170 | 130 |
| 171 def testShardBoundaryConditions(self): | 131 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 132 def testShardBoundaryConditions(self, _): |
| 172 self.shardingRangeTestHelper(1, 0) | 133 self.shardingRangeTestHelper(1, 0) |
| 173 self.shardingRangeTestHelper(1, 1) | 134 self.shardingRangeTestHelper(1, 1) |
| 174 self.shardingRangeTestHelper(2, 1) | 135 self.shardingRangeTestHelper(2, 1) |
| 175 | 136 |
| 176 def baseShardingTest(self, total_shards, shard_index, failures, successes, | 137 def baseShardingTest(self, total_shards, shard_index, failures, successes, |
| 177 opt_abbr_input_json_file=None, | 138 opt_abbr_input_json_file=None, |
| 178 opt_test_filter='', | 139 opt_test_filter='', |
| 179 opt_filter_tests_after_sharding=False): | 140 opt_filter_tests_after_sharding=False): |
| 141 options = browser_test_runner.TestRunOptions() |
| 142 options.verbosity = 0 |
| 180 config = project_config.ProjectConfig( | 143 config = project_config.ProjectConfig( |
| 181 top_level_dir=os.path.join(util.GetTelemetryDir(), 'examples'), | 144 top_level_dir=os.path.join(util.GetTelemetryDir(), 'examples'), |
| 182 client_configs=[], | 145 client_configs=['a', 'b', 'c'], |
| 183 benchmark_dirs=[ | 146 benchmark_dirs=[ |
| 184 os.path.join(util.GetTelemetryDir(), 'examples', 'browser_tests')] | 147 os.path.join(util.GetTelemetryDir(), 'examples', 'browser_tests')] |
| 185 ) | 148 ) |
| 186 temp_file = tempfile.NamedTemporaryFile(delete=False) | 149 temp_file = tempfile.NamedTemporaryFile(delete=False) |
| 187 temp_file.close() | 150 temp_file.close() |
| 188 temp_file_name = temp_file.name | 151 temp_file_name = temp_file.name |
| 189 opt_args = [] | 152 opt_args = [] |
| 190 if opt_abbr_input_json_file: | 153 if opt_abbr_input_json_file: |
| 191 opt_args += [ | 154 opt_args += [ |
| 192 '--read-abbreviated-json-results-from=%s' % opt_abbr_input_json_file] | 155 '--read-abbreviated-json-results-from=%s' % opt_abbr_input_json_file] |
| 193 if opt_test_filter: | 156 if opt_test_filter: |
| 194 opt_args += [ | 157 opt_args += [ |
| 195 '--test-filter=%s' % opt_test_filter] | 158 '--test-filter=%s' % opt_test_filter] |
| 196 if opt_filter_tests_after_sharding: | 159 if opt_filter_tests_after_sharding: |
| 197 opt_args += ['--filter-tests-after-sharding'] | 160 opt_args += ['--filter-tests-after-sharding'] |
| 198 try: | 161 try: |
| 199 browser_test_runner.Run( | 162 browser_test_runner.Run( |
| 200 config, | 163 config, options, |
| 201 ['SimpleShardingTest', | 164 ['SimpleShardingTest', |
| 202 '--write-full-results-to=%s' % temp_file_name, | 165 '--write-abbreviated-json-results-to=%s' % temp_file_name, |
| 203 '--total-shards=%d' % total_shards, | 166 '--total-shards=%d' % total_shards, |
| 204 '--shard-index=%d' % shard_index] + opt_args) | 167 '--shard-index=%d' % shard_index] + opt_args) |
| 205 with open(temp_file_name) as f: | 168 with open(temp_file_name) as f: |
| 206 test_result = json.load(f) | 169 test_result = json.load(f) |
| 207 actual_successes, actual_failures = self._ExtractTestResults(test_result) | 170 self.assertEquals(test_result['failures'], failures) |
| 208 self.assertEquals(set(actual_failures), set(failures)) | 171 self.assertEquals(test_result['successes'], successes) |
| 209 self.assertEquals(set(actual_successes), set(successes)) | 172 self.assertEquals(test_result['valid'], True) |
| 210 finally: | 173 finally: |
| 211 os.remove(temp_file_name) | 174 os.remove(temp_file_name) |
| 212 | 175 |
| 213 def testShardedTestRun(self): | 176 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 177 def testShardedTestRun(self, _): |
| 214 self.baseShardingTest(3, 0, [], [ | 178 self.baseShardingTest(3, 0, [], [ |
| 215 'browser_tests.simple_sharding_test.SimpleShardingTest.Test1', | 179 'Test1', |
| 216 'browser_tests.simple_sharding_test.SimpleShardingTest.Test2', | 180 'Test2', |
| 217 'browser_tests.simple_sharding_test.SimpleShardingTest.Test3', | 181 'Test3', |
| 218 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_0', | 182 'passing_test_0', |
| 219 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_1', | 183 'passing_test_1', |
| 220 ]) | 184 ]) |
| 221 self.baseShardingTest(3, 1, [], [ | 185 self.baseShardingTest(3, 1, [], [ |
| 222 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_2', | 186 'passing_test_2', |
| 223 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_3', | 187 'passing_test_3', |
| 224 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_4', | 188 'passing_test_4', |
| 225 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_5', | 189 'passing_test_5', |
| 226 ]) | 190 ]) |
| 227 self.baseShardingTest(3, 2, [], [ | 191 self.baseShardingTest(3, 2, [], [ |
| 228 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_6', | 192 'passing_test_6', |
| 229 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_7', | 193 'passing_test_7', |
| 230 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_8', | 194 'passing_test_8', |
| 231 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_9', | 195 'passing_test_9', |
| 232 ]) | 196 ]) |
| 233 | 197 |
| 234 def writeMockTestResultsFile(self): | 198 def writeMockTestResultsFile(self): |
| 235 mock_test_results = { | 199 mock_test_results = { |
| 236 'passes': [ | 200 'passes': [ |
| 237 'Test1', | 201 'Test1', |
| 238 'Test2', | 202 'Test2', |
| 239 'Test3', | 203 'Test3', |
| 240 'passing_test_0', | 204 'passing_test_0', |
| 241 'passing_test_1', | 205 'passing_test_1', |
| (...skipping 24 matching lines...) Expand all Loading... |
| 266 'passing_test_9': 0.5, | 230 'passing_test_9': 0.5, |
| 267 } | 231 } |
| 268 } | 232 } |
| 269 temp_file = tempfile.NamedTemporaryFile(delete=False) | 233 temp_file = tempfile.NamedTemporaryFile(delete=False) |
| 270 temp_file.close() | 234 temp_file.close() |
| 271 temp_file_name = temp_file.name | 235 temp_file_name = temp_file.name |
| 272 with open(temp_file_name, 'w') as f: | 236 with open(temp_file_name, 'w') as f: |
| 273 json.dump(mock_test_results, f) | 237 json.dump(mock_test_results, f) |
| 274 return temp_file_name | 238 return temp_file_name |
| 275 | 239 |
| 276 def testSplittingShardsByTimes(self): | 240 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 241 def testSplittingShardsByTimes(self, _): |
| 277 temp_file_name = self.writeMockTestResultsFile() | 242 temp_file_name = self.writeMockTestResultsFile() |
| 278 # It seems that the sorting order of the first four tests above is: | 243 # It seems that the sorting order of the first four tests above is: |
| 279 # passing_test_0, Test1, Test2, Test3 | 244 # passing_test_0, Test1, Test2, Test3 |
| 280 # This is probably because the relative order of the "fixed" tests | 245 # This is probably because the relative order of the "fixed" tests |
| 281 # (starting with "Test") and the generated ones ("passing_") is | 246 # (starting with "Test") and the generated ones ("passing_") is |
| 282 # not well defined, and the sorting is stable afterward. The | 247 # not well defined, and the sorting is stable afterward. The |
| 283 # expectations have been adjusted for this fact. | 248 # expectations have been adjusted for this fact. |
| 284 try: | 249 try: |
| 285 self.baseShardingTest( | 250 self.baseShardingTest( |
| 286 4, 0, [], | 251 4, 0, [], |
| 287 ['browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_0', | 252 ['passing_test_0', 'passing_test_1', |
| 288 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_1', | 253 'passing_test_5', 'passing_test_9'], |
| 289 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_5', | 254 temp_file_name) |
| 290 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_9' | |
| 291 ], temp_file_name) | |
| 292 self.baseShardingTest( | 255 self.baseShardingTest( |
| 293 4, 1, [], | 256 4, 1, [], |
| 294 ['browser_tests.simple_sharding_test.SimpleShardingTest.Test1', | 257 ['Test1', 'passing_test_2', 'passing_test_6'], |
| 295 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_2', | 258 temp_file_name) |
| 296 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_6' | |
| 297 ], temp_file_name) | |
| 298 self.baseShardingTest( | 259 self.baseShardingTest( |
| 299 4, 2, [], | 260 4, 2, [], |
| 300 ['browser_tests.simple_sharding_test.SimpleShardingTest.Test2', | 261 ['Test2', 'passing_test_3', 'passing_test_7'], |
| 301 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_3', | 262 temp_file_name) |
| 302 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_7' | |
| 303 ], temp_file_name) | |
| 304 self.baseShardingTest( | 263 self.baseShardingTest( |
| 305 4, 3, [], | 264 4, 3, [], |
| 306 ['browser_tests.simple_sharding_test.SimpleShardingTest.Test3', | 265 ['Test3', 'passing_test_4', 'passing_test_8'], |
| 307 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_4', | 266 temp_file_name) |
| 308 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_8' | |
| 309 ], temp_file_name) | |
| 310 finally: | 267 finally: |
| 311 os.remove(temp_file_name) | 268 os.remove(temp_file_name) |
| 312 | 269 |
| 313 def testFilteringAfterSharding(self): | 270 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 271 def testFilteringAfterSharding(self, _): |
| 314 temp_file_name = self.writeMockTestResultsFile() | 272 temp_file_name = self.writeMockTestResultsFile() |
| 315 try: | 273 try: |
| 316 self.baseShardingTest( | 274 self.baseShardingTest( |
| 317 4, 1, [], | 275 4, 1, [], |
| 318 ['browser_tests.simple_sharding_test.SimpleShardingTest.Test1', | 276 ['Test1', 'passing_test_2', 'passing_test_6'], |
| 319 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_2', | 277 temp_file_name, |
| 320 'browser_tests.simple_sharding_test.SimpleShardingTest.passing_test_6' | |
| 321 ], temp_file_name, | |
| 322 opt_test_filter='(Test1|passing_test_2|passing_test_6)', | 278 opt_test_filter='(Test1|passing_test_2|passing_test_6)', |
| 323 opt_filter_tests_after_sharding=True) | 279 opt_filter_tests_after_sharding=True) |
| 324 finally: | 280 finally: |
| 325 os.remove(temp_file_name) | 281 os.remove(temp_file_name) |
| 326 | 282 |
| 327 def testMedianComputation(self): | 283 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 328 self.assertEquals(2.0, run_browser_tests._MedianTestTime( | 284 def testMedianComputation(self, _): |
| 285 self.assertEquals(2.0, browser_test_runner._MedianTestTime( |
| 329 {'test1': 2.0, 'test2': 7.0, 'test3': 1.0})) | 286 {'test1': 2.0, 'test2': 7.0, 'test3': 1.0})) |
| 330 self.assertEquals(2.0, run_browser_tests._MedianTestTime( | 287 self.assertEquals(2.0, browser_test_runner._MedianTestTime( |
| 331 {'test1': 2.0})) | 288 {'test1': 2.0})) |
| 332 self.assertEquals(0.0, run_browser_tests._MedianTestTime({})) | 289 self.assertEquals(0.0, browser_test_runner._MedianTestTime({})) |
| 333 self.assertEqual(4.0, run_browser_tests._MedianTestTime( | 290 self.assertEqual(4.0, browser_test_runner._MedianTestTime( |
| 334 {'test1': 2.0, 'test2': 6.0, 'test3': 1.0, 'test4': 8.0})) | 291 {'test1': 2.0, 'test2': 6.0, 'test3': 1.0, 'test4': 8.0})) |
| 335 | 292 |
| 336 | 293 |
| 337 class Algebra( | 294 class Algebra( |
| 338 serially_executed_browser_test_case.SeriallyExecutedBrowserTestCase): | 295 serially_executed_browser_test_case.SeriallyExecutedBrowserTestCase): |
| 339 | 296 |
| 340 @classmethod | 297 @classmethod |
| 341 def GenerateTestCases_Simple(cls, options): | 298 def GenerateTestCases_Simple(cls, options): |
| 342 del options # Unused. | 299 del options # Unused. |
| 343 yield 'testOne', (1, 2) | 300 yield 'testOne', (1, 2) |
| 344 yield 'testTwo', (3, 3) | 301 yield 'testTwo', (3, 3) |
| 345 | 302 |
| 346 def Simple(self, x, y): | 303 def Simple(self, x, y): |
| 347 self.assertEquals(x, y) | 304 self.assertEquals(x, y) |
| 348 | 305 |
| 349 def TestNumber(self): | 306 def TestNumber(self): |
| 350 self.assertEquals(0, 1) | 307 self.assertEquals(0, 1) |
| 351 | 308 |
| 352 | 309 |
| 353 class ErrorneousGeometric( | 310 class Geometric( |
| 354 serially_executed_browser_test_case.SeriallyExecutedBrowserTestCase): | 311 serially_executed_browser_test_case.SeriallyExecutedBrowserTestCase): |
| 355 | 312 |
| 356 @classmethod | 313 @classmethod |
| 357 def GenerateTestCases_Compare(cls, options): | 314 def GenerateTestCases_Compare(cls, options): |
| 358 del options # Unused. | 315 del options # Unused. |
| 359 assert False, 'I am a problematic generator' | |
| 360 yield 'testBasic', ('square', 'circle') | 316 yield 'testBasic', ('square', 'circle') |
| 361 | 317 |
| 362 def Compare(self, x, y): | 318 def Compare(self, x, y): |
| 363 self.assertEquals(x, y) | 319 self.assertEquals(x, y) |
| 364 | 320 |
| 365 def TestAngle(self): | 321 def TestAngle(self): |
| 366 self.assertEquals(90, 450) | 322 self.assertEquals(90, 450) |
| 367 | 323 |
| 368 class TestLoadAllTestModules(unittest.TestCase): | 324 class TestLoadAllTestModules(unittest.TestCase): |
| 325 # TODO(nedn): this need to be updated after |
| 326 # https://codereview.chromium.org/2590623002/ is landed so that |
| 327 # LoadAllTestsInModule actually return tests. |
| 328 @decorators.Disabled('all') |
| 369 def testLoadAllTestsInModule(self): | 329 def testLoadAllTestsInModule(self): |
| 370 context = browser_test_context.TypTestContext() | 330 tests = serially_executed_browser_test_case.LoadAllTestsInModule( |
| 371 context.finder_options = options_for_unittests.GetCopy() | 331 sys.modules[__name__]) |
| 372 context.test_class = Algebra | 332 self.assertEquals(sorted([t.id() for t in tests]), |
| 373 context.test_case_ids_to_run.add( | 333 ['telemetry.testing.browser_test_runner_unittest.Algebra.TestNumber', |
| 374 'telemetry.testing.browser_test_runner_unittest.Algebra.TestNumber') | 334 'telemetry.testing.browser_test_runner_unittest.Algebra.testOne', |
| 375 context.test_case_ids_to_run.add( | 335 'telemetry.testing.browser_test_runner_unittest.Algebra.testTwo', |
| 376 'telemetry.testing.browser_test_runner_unittest.Algebra.testOne') | 336 'telemetry.testing.browser_test_runner_unittest.Geometric.TestAngle', |
| 377 context.Freeze() | 337 'telemetry.testing.browser_test_runner_unittest.Geometric.testBasic']) |
| 378 browser_test_context._global_test_context = context | |
| 379 try: | |
| 380 # This should not invoke GenerateTestCases of ErrorneousGeometric class, | |
| 381 # otherwise that would throw Exception. | |
| 382 tests = serially_executed_browser_test_case.LoadAllTestsInModule( | |
| 383 sys.modules[__name__]) | |
| 384 self.assertEquals(sorted([t.id() for t in tests]), | |
| 385 ['telemetry.testing.browser_test_runner_unittest.Algebra.TestNumber', | |
| 386 'telemetry.testing.browser_test_runner_unittest.Algebra.testOne']) | |
| 387 finally: | |
| 388 browser_test_context._global_test_context = None | |
| OLD | NEW |