| 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 from datetime import datetime | 5 from datetime import datetime |
| 6 import mock | 6 import mock |
| 7 | 7 |
| 8 from common import constants | 8 from common import constants |
| 9 from common.pipeline_wrapper import pipeline_handlers | 9 from common.pipeline_wrapper import pipeline_handlers |
| 10 from model import analysis_status | 10 from model import analysis_status |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 self.MockUTCNow(mocked_utcnow) | 55 self.MockUTCNow(mocked_utcnow) |
| 56 self.assertEqual(mocked_utcnow, | 56 self.assertEqual(mocked_utcnow, |
| 57 recursive_flake_pipeline._GetETAToStartAnalysis(True)) | 57 recursive_flake_pipeline._GetETAToStartAnalysis(True)) |
| 58 | 58 |
| 59 def testGetETAToStartAnalysisWhenTriggeredOnPSTWeekend(self): | 59 def testGetETAToStartAnalysisWhenTriggeredOnPSTWeekend(self): |
| 60 # Sunday 1pm in PST, and Sunday 8pm in UTC. | 60 # Sunday 1pm in PST, and Sunday 8pm in UTC. |
| 61 mocked_pst_now = datetime(2016, 9, 04, 13, 0, 0, 0) | 61 mocked_pst_now = datetime(2016, 9, 04, 13, 0, 0, 0) |
| 62 mocked_utc_now = datetime(2016, 9, 04, 20, 0, 0, 0) | 62 mocked_utc_now = datetime(2016, 9, 04, 20, 0, 0, 0) |
| 63 self.MockUTCNow(mocked_utc_now) | 63 self.MockUTCNow(mocked_utc_now) |
| 64 self.MockUTCNowWithTimezone(mocked_utc_now) | 64 self.MockUTCNowWithTimezone(mocked_utc_now) |
| 65 with mock.patch('lib.time_util.GetDatetimeInTimezone') as timezone_func: | 65 with mock.patch('libs.time_util.GetDatetimeInTimezone') as timezone_func: |
| 66 timezone_func.side_effect = [mocked_pst_now, None] | 66 timezone_func.side_effect = [mocked_pst_now, None] |
| 67 self.assertEqual(mocked_utc_now, | 67 self.assertEqual(mocked_utc_now, |
| 68 recursive_flake_pipeline._GetETAToStartAnalysis(False)) | 68 recursive_flake_pipeline._GetETAToStartAnalysis(False)) |
| 69 | 69 |
| 70 def testGetETAToStartAnalysisWhenTriggeredOffPeakHoursOnPSTWeekday(self): | 70 def testGetETAToStartAnalysisWhenTriggeredOffPeakHoursOnPSTWeekday(self): |
| 71 # Tuesday 1am in PST, and Tuesday 8am in UTC. | 71 # Tuesday 1am in PST, and Tuesday 8am in UTC. |
| 72 mocked_pst_now = datetime(2016, 9, 20, 1, 0, 0, 0) | 72 mocked_pst_now = datetime(2016, 9, 20, 1, 0, 0, 0) |
| 73 mocked_utc_now = datetime(2016, 9, 20, 8, 0, 0, 0) | 73 mocked_utc_now = datetime(2016, 9, 20, 8, 0, 0, 0) |
| 74 self.MockUTCNow(mocked_utc_now) | 74 self.MockUTCNow(mocked_utc_now) |
| 75 self.MockUTCNowWithTimezone(mocked_utc_now) | 75 self.MockUTCNowWithTimezone(mocked_utc_now) |
| 76 with mock.patch('lib.time_util.GetDatetimeInTimezone') as timezone_func: | 76 with mock.patch('libs.time_util.GetDatetimeInTimezone') as timezone_func: |
| 77 timezone_func.side_effect = [mocked_pst_now, None] | 77 timezone_func.side_effect = [mocked_pst_now, None] |
| 78 self.assertEqual(mocked_utc_now, | 78 self.assertEqual(mocked_utc_now, |
| 79 recursive_flake_pipeline._GetETAToStartAnalysis(False)) | 79 recursive_flake_pipeline._GetETAToStartAnalysis(False)) |
| 80 | 80 |
| 81 def testGetETAToStartAnalysisWhenTriggeredInPeakHoursOnPSTWeekday(self): | 81 def testGetETAToStartAnalysisWhenTriggeredInPeakHoursOnPSTWeekday(self): |
| 82 # Tuesday 1pm in PST, and Tuesday 8pm in UTC. | 82 # Tuesday 1pm in PST, and Tuesday 8pm in UTC. |
| 83 seconds_delay = 10 | 83 seconds_delay = 10 |
| 84 mocked_pst_now = datetime(2016, 9, 20, 13, 0, 0, 0) | 84 mocked_pst_now = datetime(2016, 9, 20, 13, 0, 0, 0) |
| 85 mocked_utc_now = datetime(2016, 9, 20, 20, 0, 0, 0) | 85 mocked_utc_now = datetime(2016, 9, 20, 20, 0, 0, 0) |
| 86 mocked_pst_eta = datetime( | 86 mocked_pst_eta = datetime( |
| 87 2016, 9, 20, 18, 0, seconds_delay, 0) # With arbitrary delay of 10s. | 87 2016, 9, 20, 18, 0, seconds_delay, 0) # With arbitrary delay of 10s. |
| 88 mocked_utc_eta = datetime(2016, 9, 21, 1, 0, 0, 0) # Without delay. | 88 mocked_utc_eta = datetime(2016, 9, 21, 1, 0, 0, 0) # Without delay. |
| 89 self.MockUTCNow(mocked_utc_now) | 89 self.MockUTCNow(mocked_utc_now) |
| 90 self.MockUTCNowWithTimezone(mocked_utc_now) | 90 self.MockUTCNowWithTimezone(mocked_utc_now) |
| 91 with mock.patch('lib.time_util.GetDatetimeInTimezone') as ( | 91 with mock.patch('libs.time_util.GetDatetimeInTimezone') as ( |
| 92 timezone_func), mock.patch('random.randint') as random_func: | 92 timezone_func), mock.patch('random.randint') as random_func: |
| 93 timezone_func.side_effect = [mocked_pst_now, mocked_utc_eta] | 93 timezone_func.side_effect = [mocked_pst_now, mocked_utc_eta] |
| 94 random_func.side_effect = [seconds_delay, None] | 94 random_func.side_effect = [seconds_delay, None] |
| 95 self.assertEqual(mocked_utc_eta, | 95 self.assertEqual(mocked_utc_eta, |
| 96 recursive_flake_pipeline._GetETAToStartAnalysis(False)) | 96 recursive_flake_pipeline._GetETAToStartAnalysis(False)) |
| 97 self.assertEqual(2, timezone_func.call_count) | 97 self.assertEqual(2, timezone_func.call_count) |
| 98 self.assertEqual(mock.call('US/Pacific', mocked_utc_now), | 98 self.assertEqual(mock.call('US/Pacific', mocked_utc_now), |
| 99 timezone_func.call_args_list[0]) | 99 timezone_func.call_args_list[0]) |
| 100 self.assertEqual(mock.call('UTC', mocked_pst_eta), | 100 self.assertEqual(mock.call('UTC', mocked_pst_eta), |
| 101 timezone_func.call_args_list[1]) | 101 timezone_func.call_args_list[1]) |
| (...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 calls = mocked_pipeline.mock_calls | 1327 calls = mocked_pipeline.mock_calls |
| 1328 self.assertEqual(2, len(calls)) | 1328 self.assertEqual(2, len(calls)) |
| 1329 | 1329 |
| 1330 _, args, __ = calls[0] | 1330 _, args, __ = calls[0] |
| 1331 bug_id, comment, labels = args | 1331 bug_id, comment, labels = args |
| 1332 self.assertEqual(123, bug_id) | 1332 self.assertEqual(123, bug_id) |
| 1333 self.assertEqual(['AnalyzedByFindit'], labels) | 1333 self.assertEqual(['AnalyzedByFindit'], labels) |
| 1334 self.assertTrue('om / ob / os' in comment) | 1334 self.assertTrue('om / ob / os' in comment) |
| 1335 | 1335 |
| 1336 self.assertEqual(mock.call().start(queue_name='queue'), calls[1]) | 1336 self.assertEqual(mock.call().start(queue_name='queue'), calls[1]) |
| OLD | NEW |