Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 sys | 6 import sys |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 # TODO(robertocn): Use abspath for these, to prevent relative path errors. | 9 # TODO(robertocn): Use abspath for these, to prevent relative path errors. |
| 10 _RECIPE_MODULES_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir) | 10 _RECIPE_MODULES_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir) |
| 11 # For the importing of mock. | 11 # For the importing of mock. |
| 12 _ROOT_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir, | 12 _ROOT_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir, |
| 13 os.path.pardir, os.path.pardir, os.path.pardir) | 13 os.path.pardir, os.path.pardir, os.path.pardir) |
| 14 | 14 |
| 15 sys.path.append(_RECIPE_MODULES_DIR) | 15 sys.path.append(_RECIPE_MODULES_DIR) |
| 16 sys.path.append(os.path.join(_ROOT_DIR, 'third_party', 'mock-1.0.1')) | 16 sys.path.append(os.path.join(_ROOT_DIR, 'third_party', 'mock-1.0.1')) |
| 17 | 17 |
| 18 import mock | 18 import mock |
| 19 | 19 |
| 20 from auto_bisect.bisector import Bisector | 20 from auto_bisect.bisector import Bisector |
| 21 | 21 |
| 22 # Globals | |
| 23 called_abort = False | |
| 24 aborted_once = False | |
| 25 | |
| 22 class BisectorTest(unittest.TestCase): | 26 class BisectorTest(unittest.TestCase): |
| 23 def setUp(self): | 27 def setUp(self): |
| 24 self.bisect_config = { | 28 self.bisect_config = { |
| 25 'test_type': 'perf', | 29 'test_type': 'perf', |
| 26 'command': 'tools/perf/run_benchmark -v ' | 30 'command': 'tools/perf/run_benchmark -v ' |
| 27 '--browser=release page_cycler.intl_ar_fa_he', | 31 '--browser=release page_cycler.intl_ar_fa_he', |
| 28 'good_revision': '306475', | 32 'good_revision': '306475', |
| 29 'bad_revision': '306478', | 33 'bad_revision': '306478', |
| 30 'metric': 'warm_times/page_load_time', | 34 'metric': 'warm_times/page_load_time', |
| 31 'repeat_count': '2', | 35 'repeat_count': '2', |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 r.in_progress = True | 198 r.in_progress = True |
| 195 new_bisector.revisions[0].tested = True | 199 new_bisector.revisions[0].tested = True |
| 196 finished_revision = new_bisector.wait_for_any(new_bisector.revisions) | 200 finished_revision = new_bisector.wait_for_any(new_bisector.revisions) |
| 197 self.assertEqual(new_bisector.revisions[0], finished_revision) | 201 self.assertEqual(new_bisector.revisions[0], finished_revision) |
| 198 | 202 |
| 199 def test_abort_unnecessary_jobs(self): | 203 def test_abort_unnecessary_jobs(self): |
| 200 global aborted_once, called_abort | 204 global aborted_once, called_abort |
| 201 called_abort = False | 205 called_abort = False |
| 202 aborted_once = False | 206 aborted_once = False |
| 203 | 207 |
| 204 def mock_abort(s): | 208 def mock_abort(_): |
| 205 global aborted_once, called_abort | 209 global aborted_once, called_abort |
| 206 called_abort = True | 210 called_abort = True |
| 207 if aborted_once: | 211 if aborted_once: |
| 208 raise Exception('Only one abort expected') | 212 raise RuntimeError('Only one abort expected') |
| 209 aborted_once = True | 213 aborted_once = True |
| 210 | 214 |
| 211 self.MockRevisionClass.abort = None | 215 self.MockRevisionClass.abort = None |
| 212 self.MockRevisionClass.update_status = None | 216 self.MockRevisionClass.update_status = None |
| 213 with mock.patch( | 217 with mock.patch( |
| 214 'bisector_test.BisectorTest.MockRevisionClass.update_status'): | 218 'bisector_test.BisectorTest.MockRevisionClass.update_status'): |
| 215 with mock.patch('bisector_test.BisectorTest.MockRevisionClass.abort', | 219 with mock.patch('bisector_test.BisectorTest.MockRevisionClass.abort', |
| 216 mock_abort) as abort_patch: | 220 mock_abort): |
| 217 new_bisector = Bisector(self.dummy_api, self.bisect_config, | 221 new_bisector = Bisector(self.dummy_api, self.bisect_config, |
| 218 self.MockRevisionClass) | 222 self.MockRevisionClass) |
| 219 r = new_bisector.revisions | 223 r = new_bisector.revisions |
| 220 r[0].good = True | 224 r[0].good = True |
| 221 r[0].bad = False | 225 r[0].bad = False |
| 222 r[0].tested = True | 226 r[0].tested = True |
| 223 r[0].in_progress = False | 227 r[0].in_progress = False |
| 224 | 228 |
| 225 r[1].in_progress = True | 229 r[1].in_progress = True |
| 226 r[1].tested = False | 230 r[1].tested = False |
| 227 | 231 |
| 228 r[2].good = True | 232 r[2].good = True |
| 229 r[2].bad = False | 233 r[2].bad = False |
| 230 r[2].tested = True | 234 r[2].tested = True |
| 231 r[2].in_progress = False | 235 r[2].in_progress = False |
| 232 | 236 |
| 233 r[3].bad = True | 237 r[3].bad = True |
| 234 r[3].good = False | 238 r[3].good = False |
| 235 r[3].tested = True | 239 r[3].tested = True |
| 236 r[3].in_progress = False | 240 r[3].in_progress = False |
| 237 | 241 |
| 238 try: | 242 try: |
| 239 new_bisector.abort_unnecessary_jobs() | 243 new_bisector.abort_unnecessary_jobs() |
| 240 except: | 244 except RuntimeError: |
| 241 self.fail('Expected to call abort only once') | 245 self.fail('Expected to call abort only once') |
| 242 self.assertTrue(called_abort) | 246 self.assertTrue(called_abort) |
|
qyearsley
2015/02/22 20:37:55
Would it be possible to do this without global var
RobertoCN
2015/02/24 20:01:14
Done.
| |
| 243 | 247 |
| 244 # Verifying the side effects of updating the candidate range | 248 # Verifying the side effects of updating the candidate range |
| 245 self.assertEqual(r[2], new_bisector.lkgr) | 249 self.assertEqual(r[2], new_bisector.lkgr) |
| 246 self.assertEqual(r[3], new_bisector.fkbr) | 250 self.assertEqual(r[3], new_bisector.fkbr) |
| 247 | 251 |
| 248 # TODO: Test check_bisect_finished | 252 # TODO(robertocn): Add test for bisector.check_bisect_finished. |
| 249 | |
| 250 | |
| 251 if __name__ == '__main__': | 253 if __name__ == '__main__': |
| 252 unittest.main() | 254 unittest.main() |
| OLD | NEW |