| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 # Use of this source code is governed by the Apache v2.0 license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import datetime | 6 import datetime |
| 7 import inspect | 7 import inspect |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import random | 10 import random |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 _result_summary = task_scheduler.schedule_request(request) | 395 _result_summary = task_scheduler.schedule_request(request) |
| 396 # The task was enqueued for execution. | 396 # The task was enqueued for execution. |
| 397 self.assertNotEqual(None, task_to_run.TaskToRun.query().get().queue_number) | 397 self.assertNotEqual(None, task_to_run.TaskToRun.query().get().queue_number) |
| 398 | 398 |
| 399 def test_task_idempotent_variable(self): | 399 def test_task_idempotent_variable(self): |
| 400 # Test the edge case where GlobalConfig.reusable_task_age_secs is being | 400 # Test the edge case where GlobalConfig.reusable_task_age_secs is being |
| 401 # modified. This ensure TaskResultSummary.order(TRS.key) works. | 401 # modified. This ensure TaskResultSummary.order(TRS.key) works. |
| 402 self.mock(random, 'getrandbits', lambda _: 0x88) | 402 self.mock(random, 'getrandbits', lambda _: 0x88) |
| 403 cfg = config.settings() | 403 cfg = config.settings() |
| 404 cfg.reusable_task_age_secs = 10 | 404 cfg.reusable_task_age_secs = 10 |
| 405 cfg.store() | 405 self.mock(config, 'settings', lambda: cfg) |
| 406 | 406 |
| 407 # First task is idempotent. | 407 # First task is idempotent. |
| 408 self._task_ran_successfully() | 408 self._task_ran_successfully() |
| 409 | 409 |
| 410 # Second task is scheduled, first task is too old to be reused. | 410 # Second task is scheduled, first task is too old to be reused. |
| 411 second_ts = self.mock_now(self.now, 10) | 411 second_ts = self.mock_now(self.now, 10) |
| 412 task_id = self._task_ran_successfully() | 412 task_id = self._task_ran_successfully() |
| 413 | 413 |
| 414 # Now any of the 2 tasks could be reused. Assert the right one (the most | 414 # Now any of the 2 tasks could be reused. Assert the right one (the most |
| 415 # recent) is reused. | 415 # recent) is reused. |
| 416 cfg = config.settings() | |
| 417 cfg.reusable_task_age_secs = 100 | 416 cfg.reusable_task_age_secs = 100 |
| 418 cfg.store() | |
| 419 | 417 |
| 420 # Third task is deduped against second task. That ensures ordering works | 418 # Third task is deduped against second task. That ensures ordering works |
| 421 # correctly. | 419 # correctly. |
| 422 third_ts = self.mock_now(self.now, 20) | 420 third_ts = self.mock_now(self.now, 20) |
| 423 self._task_deduped(third_ts, task_id, '1d69ba3ea8008810', second_ts) | 421 self._task_deduped(third_ts, task_id, '1d69ba3ea8008810', second_ts) |
| 424 | 422 |
| 425 def test_task_parent_children(self): | 423 def test_task_parent_children(self): |
| 426 # Parent task creates a child task. | 424 # Parent task creates a child task. |
| 427 parent_id = self._task_ran_successfully() | 425 parent_id = self._task_ran_successfully() |
| 428 data = _gen_request( | 426 data = _gen_request( |
| (...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 actual, cursor = task_result._search_by_name('Request', cursor, 31) | 1725 actual, cursor = task_result._search_by_name('Request', cursor, 31) |
| 1728 self.assertEqual(0, len(actual)) | 1726 self.assertEqual(0, len(actual)) |
| 1729 | 1727 |
| 1730 | 1728 |
| 1731 if __name__ == '__main__': | 1729 if __name__ == '__main__': |
| 1732 if '-v' in sys.argv: | 1730 if '-v' in sys.argv: |
| 1733 unittest.TestCase.maxDiff = None | 1731 unittest.TestCase.maxDiff = None |
| 1734 logging.basicConfig( | 1732 logging.basicConfig( |
| 1735 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) | 1733 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
| 1736 unittest.main() | 1734 unittest.main() |
| OLD | NEW |