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

Side by Side Diff: appengine/findit/waterfall/flake/test/recursive_flake_pipeline_test.py

Issue 2480593002: [Predator] Move time_util from common/ to lib/, split code review related part to code_review_util (Closed)
Patch Set: Rebase and fix nits. Created 4 years, 1 month 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 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 self.MockUTCNow(mocked_utcnow) 53 self.MockUTCNow(mocked_utcnow)
54 self.assertEqual(mocked_utcnow, 54 self.assertEqual(mocked_utcnow,
55 recursive_flake_pipeline._GetETAToStartAnalysis(True)) 55 recursive_flake_pipeline._GetETAToStartAnalysis(True))
56 56
57 def testGetETAToStartAnalysisWhenTriggeredOnPSTWeekend(self): 57 def testGetETAToStartAnalysisWhenTriggeredOnPSTWeekend(self):
58 # Sunday 1pm in PST, and Sunday 8pm in UTC. 58 # Sunday 1pm in PST, and Sunday 8pm in UTC.
59 mocked_pst_now = datetime(2016, 9, 04, 13, 0, 0, 0) 59 mocked_pst_now = datetime(2016, 9, 04, 13, 0, 0, 0)
60 mocked_utc_now = datetime(2016, 9, 04, 20, 0, 0, 0) 60 mocked_utc_now = datetime(2016, 9, 04, 20, 0, 0, 0)
61 self.MockUTCNow(mocked_utc_now) 61 self.MockUTCNow(mocked_utc_now)
62 self.MockUTCNowWithTimezone(mocked_utc_now) 62 self.MockUTCNowWithTimezone(mocked_utc_now)
63 with mock.patch('common.time_util.GetDatetimeInTimezone') as timezone_func: 63 with mock.patch('lib.time_util.GetDatetimeInTimezone') as timezone_func:
64 timezone_func.side_effect = [mocked_pst_now, None] 64 timezone_func.side_effect = [mocked_pst_now, None]
65 self.assertEqual(mocked_utc_now, 65 self.assertEqual(mocked_utc_now,
66 recursive_flake_pipeline._GetETAToStartAnalysis(False)) 66 recursive_flake_pipeline._GetETAToStartAnalysis(False))
67 67
68 def testGetETAToStartAnalysisWhenTriggeredOffPeakHoursOnPSTWeekday(self): 68 def testGetETAToStartAnalysisWhenTriggeredOffPeakHoursOnPSTWeekday(self):
69 # Tuesday 1am in PST, and Tuesday 8am in UTC. 69 # Tuesday 1am in PST, and Tuesday 8am in UTC.
70 mocked_pst_now = datetime(2016, 9, 20, 1, 0, 0, 0) 70 mocked_pst_now = datetime(2016, 9, 20, 1, 0, 0, 0)
71 mocked_utc_now = datetime(2016, 9, 20, 8, 0, 0, 0) 71 mocked_utc_now = datetime(2016, 9, 20, 8, 0, 0, 0)
72 self.MockUTCNow(mocked_utc_now) 72 self.MockUTCNow(mocked_utc_now)
73 self.MockUTCNowWithTimezone(mocked_utc_now) 73 self.MockUTCNowWithTimezone(mocked_utc_now)
74 with mock.patch('common.time_util.GetDatetimeInTimezone') as timezone_func: 74 with mock.patch('lib.time_util.GetDatetimeInTimezone') as timezone_func:
75 timezone_func.side_effect = [mocked_pst_now, None] 75 timezone_func.side_effect = [mocked_pst_now, None]
76 self.assertEqual(mocked_utc_now, 76 self.assertEqual(mocked_utc_now,
77 recursive_flake_pipeline._GetETAToStartAnalysis(False)) 77 recursive_flake_pipeline._GetETAToStartAnalysis(False))
78 78
79 def testGetETAToStartAnalysisWhenTriggeredInPeakHoursOnPSTWeekday(self): 79 def testGetETAToStartAnalysisWhenTriggeredInPeakHoursOnPSTWeekday(self):
80 # Tuesday 1pm in PST, and Tuesday 8pm in UTC. 80 # Tuesday 1pm in PST, and Tuesday 8pm in UTC.
81 seconds_delay = 10 81 seconds_delay = 10
82 mocked_pst_now = datetime(2016, 9, 20, 13, 0, 0, 0) 82 mocked_pst_now = datetime(2016, 9, 20, 13, 0, 0, 0)
83 mocked_utc_now = datetime(2016, 9, 20, 20, 0, 0, 0) 83 mocked_utc_now = datetime(2016, 9, 20, 20, 0, 0, 0)
84 mocked_pst_eta = datetime( 84 mocked_pst_eta = datetime(
85 2016, 9, 20, 18, 0, seconds_delay, 0) # With arbitrary delay of 10s. 85 2016, 9, 20, 18, 0, seconds_delay, 0) # With arbitrary delay of 10s.
86 mocked_utc_eta = datetime(2016, 9, 21, 1, 0, 0, 0) # Without delay. 86 mocked_utc_eta = datetime(2016, 9, 21, 1, 0, 0, 0) # Without delay.
87 self.MockUTCNow(mocked_utc_now) 87 self.MockUTCNow(mocked_utc_now)
88 self.MockUTCNowWithTimezone(mocked_utc_now) 88 self.MockUTCNowWithTimezone(mocked_utc_now)
89 with mock.patch('common.time_util.GetDatetimeInTimezone') as ( 89 with mock.patch('lib.time_util.GetDatetimeInTimezone') as (
90 timezone_func), mock.patch('random.randint') as random_func: 90 timezone_func), mock.patch('random.randint') as random_func:
91 timezone_func.side_effect = [mocked_pst_now, mocked_utc_eta] 91 timezone_func.side_effect = [mocked_pst_now, mocked_utc_eta]
92 random_func.side_effect = [seconds_delay, None] 92 random_func.side_effect = [seconds_delay, None]
93 self.assertEqual(mocked_utc_eta, 93 self.assertEqual(mocked_utc_eta,
94 recursive_flake_pipeline._GetETAToStartAnalysis(False)) 94 recursive_flake_pipeline._GetETAToStartAnalysis(False))
95 self.assertEqual(2, timezone_func.call_count) 95 self.assertEqual(2, timezone_func.call_count)
96 self.assertEqual(mock.call('US/Pacific', mocked_utc_now), 96 self.assertEqual(mock.call('US/Pacific', mocked_utc_now),
97 timezone_func.call_args_list[0]) 97 timezone_func.call_args_list[0])
98 self.assertEqual(mock.call('UTC', mocked_pst_eta), 98 self.assertEqual(mock.call('UTC', mocked_pst_eta),
99 timezone_func.call_args_list[1]) 99 timezone_func.call_args_list[1])
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 analysis = MasterFlakeAnalysis.GetVersion( 874 analysis = MasterFlakeAnalysis.GetVersion(
875 master_name, builder_name, master_build_number, step_name, test_name) 875 master_name, builder_name, master_build_number, step_name, test_name)
876 self.assertEqual(analysis_status.COMPLETED, analysis.status) 876 self.assertEqual(analysis_status.COMPLETED, analysis.status)
877 877
878 def testUpdateAnalysisUponCompletionFound(self): 878 def testUpdateAnalysisUponCompletionFound(self):
879 analysis = MasterFlakeAnalysis.Create('m', 'b', 123, 's', 't') 879 analysis = MasterFlakeAnalysis.Create('m', 'b', 123, 's', 't')
880 analysis.suspected_flake_build_number = 100 880 analysis.suspected_flake_build_number = 100
881 recursive_flake_pipeline._UpdateAnalysisStatusUponCompletion( 881 recursive_flake_pipeline._UpdateAnalysisStatusUponCompletion(
882 analysis, analysis_status.COMPLETED, None) 882 analysis, analysis_status.COMPLETED, None)
883 self.assertEqual(analysis.result_status, result_status.FOUND_UNTRIAGED) 883 self.assertEqual(analysis.result_status, result_status.FOUND_UNTRIAGED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698