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

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

Issue 2391063002: [Findit] Fix flaky tests due to importing pytz. (Closed)
Patch Set: Fix nit. Created 4 years, 2 months 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
« no previous file with comments | « appengine/findit/waterfall/flake/recursive_flake_pipeline.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6 import mock
7 import pytz
8 7
9 from common import constants 8 from common import constants
10 from common.pipeline_wrapper import pipeline_handlers 9 from common.pipeline_wrapper import pipeline_handlers
11 from model import analysis_status 10 from model import analysis_status
12 from model.flake.flake_swarming_task import FlakeSwarmingTask 11 from model.flake.flake_swarming_task import FlakeSwarmingTask
13 from model.flake.master_flake_analysis import DataPoint 12 from model.flake.master_flake_analysis import DataPoint
14 from model.flake.master_flake_analysis import MasterFlakeAnalysis 13 from model.flake.master_flake_analysis import MasterFlakeAnalysis
15 from waterfall.flake import recursive_flake_pipeline 14 from waterfall.flake import recursive_flake_pipeline
16 from waterfall.flake.recursive_flake_pipeline import get_next_run 15 from waterfall.flake.recursive_flake_pipeline import get_next_run
17 from waterfall.flake.recursive_flake_pipeline import NextBuildNumberPipeline 16 from waterfall.flake.recursive_flake_pipeline import NextBuildNumberPipeline
(...skipping 30 matching lines...) Expand all
48 data_points.append(data_point) 47 data_points.append(data_point)
49 return data_points 48 return data_points
50 49
51 def testGetETAToStartAnalysisWhenManuallyTriggered(self): 50 def testGetETAToStartAnalysisWhenManuallyTriggered(self):
52 mocked_utcnow = datetime.utcnow() 51 mocked_utcnow = datetime.utcnow()
53 self.MockUTCNow(mocked_utcnow) 52 self.MockUTCNow(mocked_utcnow)
54 self.assertEqual(mocked_utcnow, 53 self.assertEqual(mocked_utcnow,
55 recursive_flake_pipeline._GetETAToStartAnalysis(True)) 54 recursive_flake_pipeline._GetETAToStartAnalysis(True))
56 55
57 def testGetETAToStartAnalysisWhenTriggeredOnPSTWeekend(self): 56 def testGetETAToStartAnalysisWhenTriggeredOnPSTWeekend(self):
58 # Sunday 1pm in PST. 57 # Sunday 1pm in PST, and Sunday 8pm in UTC.
59 mocked_utcnow = datetime(2016, 9, 04, 20, 0, 0, 0, pytz.utc) 58 mocked_pst_now = datetime(2016, 9, 04, 13, 0, 0, 0)
60 self.MockUTCNow(mocked_utcnow) 59 mocked_utc_now = datetime(2016, 9, 04, 20, 0, 0, 0)
61 self.MockUTCNowWithTimezone(mocked_utcnow) 60 self.MockUTCNow(mocked_utc_now)
62 self.assertEqual(mocked_utcnow, 61 self.MockUTCNowWithTimezone(mocked_utc_now)
63 recursive_flake_pipeline._GetETAToStartAnalysis(False)) 62 with mock.patch('common.time_util.GetDatetimeInTimezone') as timezone_func:
63 timezone_func.side_effect = [mocked_pst_now, None]
64 self.assertEqual(mocked_utc_now,
65 recursive_flake_pipeline._GetETAToStartAnalysis(False))
64 66
65 def testGetETAToStartAnalysisWhenTriggeredOffPeakHoursOnPSTWeekday(self): 67 def testGetETAToStartAnalysisWhenTriggeredOffPeakHoursOnPSTWeekday(self):
66 # Tuesday 1am in PST. 68 # Tuesday 1am in PST, and Tuesday 8am in UTC.
67 mocked_utcnow = datetime(2016, 9, 20, 8, 0, 0, 0, pytz.utc) 69 mocked_pst_now = datetime(2016, 9, 20, 1, 0, 0, 0)
68 self.MockUTCNow(mocked_utcnow) 70 mocked_utc_now = datetime(2016, 9, 20, 8, 0, 0, 0)
69 self.MockUTCNowWithTimezone(mocked_utcnow) 71 self.MockUTCNow(mocked_utc_now)
70 self.assertEqual(mocked_utcnow, 72 self.MockUTCNowWithTimezone(mocked_utc_now)
71 recursive_flake_pipeline._GetETAToStartAnalysis(False)) 73 with mock.patch('common.time_util.GetDatetimeInTimezone') as timezone_func:
74 timezone_func.side_effect = [mocked_pst_now, None]
75 self.assertEqual(mocked_utc_now,
76 recursive_flake_pipeline._GetETAToStartAnalysis(False))
72 77
73 def testGetETAToStartAnalysisWhenTriggeredInPeakHoursOnPSTWeekday(self): 78 def testGetETAToStartAnalysisWhenTriggeredInPeakHoursOnPSTWeekday(self):
74 # Tuesday 1pm in PST. 79 # Tuesday 1pm in PST, and Tuesday 8pm in UTC.
75 mocked_utcnow = datetime(2016, 9, 20, 20, 0, 0, 0, pytz.utc) 80 seconds_delay = 10
76 self.MockUTCNow(mocked_utcnow) 81 mocked_pst_now = datetime(2016, 9, 20, 13, 0, 0, 0)
77 self.MockUTCNowWithTimezone(mocked_utcnow) 82 mocked_utc_now = datetime(2016, 9, 20, 20, 0, 0, 0)
78 eta = recursive_flake_pipeline._GetETAToStartAnalysis(False) 83 mocked_pst_eta = datetime(
79 self.assertEqual(2016, eta.year) 84 2016, 9, 20, 18, 0, seconds_delay, 0) # With arbitrary delay of 10s.
80 self.assertEqual(9, eta.month) 85 mocked_utc_eta = datetime(2016, 9, 21, 1, 0, 0, 0) # Without delay.
81 self.assertEqual(21, eta.day) 86 self.MockUTCNow(mocked_utc_now)
82 self.assertEqual(1, eta.hour) 87 self.MockUTCNowWithTimezone(mocked_utc_now)
83 seconds = eta.minute * 60 + eta.second 88 with mock.patch('common.time_util.GetDatetimeInTimezone') as (
84 self.assertTrue(seconds >= 0 and seconds <= 30 * 60) 89 timezone_func), mock.patch('random.randint') as random_func:
90 timezone_func.side_effect = [mocked_pst_now, mocked_utc_eta]
91 random_func.side_effect = [seconds_delay, None]
92 self.assertEqual(mocked_utc_eta,
93 recursive_flake_pipeline._GetETAToStartAnalysis(False))
94 self.assertEqual(2, timezone_func.call_count)
95 self.assertEqual(mock.call('US/Pacific', mocked_utc_now),
96 timezone_func.call_args_list[0])
97 self.assertEqual(mock.call('UTC', mocked_pst_eta),
98 timezone_func.call_args_list[1])
85 99
86 def testRecursiveFlakePipeline(self): 100 def testRecursiveFlakePipeline(self):
87 master_name = 'm' 101 master_name = 'm'
88 builder_name = 'b' 102 builder_name = 'b'
89 master_build_number = 100 103 master_build_number = 100
90 build_number = 100 104 build_number = 100
91 run_build_number = 100 105 run_build_number = 100
92 step_name = 's' 106 step_name = 's'
93 test_name = 't' 107 test_name = 't'
94 test_result_future = 'test_result_future' 108 test_result_future = 'test_result_future'
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 expected_kwargs={'manually_triggered': False}) 153 expected_kwargs={'manually_triggered': False})
140 154
141 rfp = RecursiveFlakePipeline( 155 rfp = RecursiveFlakePipeline(
142 master_name, builder_name, build_number, step_name, test_name, 156 master_name, builder_name, build_number, step_name, test_name,
143 analysis.version_number, master_build_number, 157 analysis.version_number, master_build_number,
144 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict) 158 flakiness_algorithm_results_dict=flakiness_algorithm_results_dict)
145 159
146 rfp.start(queue_name=queue_name) 160 rfp.start(queue_name=queue_name)
147 self.execute_queued_tasks() 161 self.execute_queued_tasks()
148 162
149 def testNextBuildPipelineForNewRecursionFirstFlake(self): 163 @mock.patch.object(
164 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
165 def testNextBuildPipelineForNewRecursionFirstFlake(self, _mocked_eta_func):
150 master_name = 'm' 166 master_name = 'm'
151 builder_name = 'b' 167 builder_name = 'b'
152 master_build_number = 100 168 master_build_number = 100
153 build_number = 100 169 build_number = 100
154 step_name = 's' 170 step_name = 's'
155 test_name = 't' 171 test_name = 't'
156 test_result_future = 'trf' 172 test_result_future = 'trf'
157 flakiness_algorithm_results_dict = { 173 flakiness_algorithm_results_dict = {
158 'flakes_in_a_row': 0, 174 'flakes_in_a_row': 0,
159 'stable_in_a_row': 0, 175 'stable_in_a_row': 0,
(...skipping 23 matching lines...) Expand all
183 analysis.data_points.append(data_point) 199 analysis.data_points.append(data_point)
184 analysis.put() 200 analysis.put()
185 201
186 NextBuildNumberPipeline.run( 202 NextBuildNumberPipeline.run(
187 NextBuildNumberPipeline(), master_name, builder_name, 203 NextBuildNumberPipeline(), master_name, builder_name,
188 master_build_number, build_number, step_name, test_name, 204 master_build_number, build_number, step_name, test_name,
189 analysis.version_number, test_result_future, 205 analysis.version_number, test_result_future,
190 flakiness_algorithm_results_dict) 206 flakiness_algorithm_results_dict)
191 self.assertEquals(flakiness_algorithm_results_dict['flakes_in_a_row'], 1) 207 self.assertEquals(flakiness_algorithm_results_dict['flakes_in_a_row'], 1)
192 208
193 def testNextBuildPipelineForNewRecursionFirstStable(self): 209 @mock.patch.object(
210 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
211 def testNextBuildPipelineForNewRecursionFirstStable(self, _mocked_eta_func):
194 master_name = 'm' 212 master_name = 'm'
195 builder_name = 'b' 213 builder_name = 'b'
196 master_build_number = 100 214 master_build_number = 100
197 build_number = 100 215 build_number = 100
198 step_name = 's' 216 step_name = 's'
199 test_name = 't' 217 test_name = 't'
200 test_result_future = 'trf' 218 test_result_future = 'trf'
201 flakiness_algorithm_results_dict = { 219 flakiness_algorithm_results_dict = {
202 'flakes_in_a_row': 0, 220 'flakes_in_a_row': 0,
203 'stable_in_a_row': 0, 221 'stable_in_a_row': 0,
(...skipping 21 matching lines...) Expand all
225 analysis.data_points.append(data_point) 243 analysis.data_points.append(data_point)
226 analysis.put() 244 analysis.put()
227 245
228 NextBuildNumberPipeline.run( 246 NextBuildNumberPipeline.run(
229 NextBuildNumberPipeline(), master_name, builder_name, 247 NextBuildNumberPipeline(), master_name, builder_name,
230 master_build_number, build_number, step_name, 248 master_build_number, build_number, step_name,
231 test_name, analysis.version_number, test_result_future, 249 test_name, analysis.version_number, test_result_future,
232 flakiness_algorithm_results_dict) 250 flakiness_algorithm_results_dict)
233 self.assertEquals(flakiness_algorithm_results_dict['stable_in_a_row'], 1) 251 self.assertEquals(flakiness_algorithm_results_dict['stable_in_a_row'], 1)
234 252
235 def testNextBuildPipelineForNewRecursionFlakeInARow(self): 253 @mock.patch.object(
254 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
255 def testNextBuildPipelineForNewRecursionFlakeInARow(self, _mocked_eta_func):
236 master_name = 'm' 256 master_name = 'm'
237 builder_name = 'b' 257 builder_name = 'b'
238 master_build_number = 100 258 master_build_number = 100
239 build_number = 100 259 build_number = 100
240 step_name = 's' 260 step_name = 's'
241 test_name = 't' 261 test_name = 't'
242 test_result_future = 'trf' 262 test_result_future = 'trf'
243 flakiness_algorithm_results_dict = { 263 flakiness_algorithm_results_dict = {
244 'flakes_in_a_row': 0, 264 'flakes_in_a_row': 0,
245 'stable_in_a_row': 4, 265 'stable_in_a_row': 4,
(...skipping 22 matching lines...) Expand all
268 analysis.data_points.append(data_point) 288 analysis.data_points.append(data_point)
269 analysis.put() 289 analysis.put()
270 290
271 NextBuildNumberPipeline.run( 291 NextBuildNumberPipeline.run(
272 NextBuildNumberPipeline(), master_name, builder_name, 292 NextBuildNumberPipeline(), master_name, builder_name,
273 master_build_number, build_number, step_name, 293 master_build_number, build_number, step_name,
274 test_name, analysis.version_number, test_result_future, 294 test_name, analysis.version_number, test_result_future,
275 flakiness_algorithm_results_dict) 295 flakiness_algorithm_results_dict)
276 self.assertEquals(flakiness_algorithm_results_dict['stabled_out'], True) 296 self.assertEquals(flakiness_algorithm_results_dict['stabled_out'], True)
277 297
278 def testNextBuildPipelineForNewRecursionStableInARow(self): 298 @mock.patch.object(
299 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
300 def testNextBuildPipelineForNewRecursionStableInARow(self, _mocked_eta_func):
279 master_name = 'm' 301 master_name = 'm'
280 builder_name = 'b' 302 builder_name = 'b'
281 master_build_number = 100 303 master_build_number = 100
282 build_number = 100 304 build_number = 100
283 step_name = 's' 305 step_name = 's'
284 test_name = 't' 306 test_name = 't'
285 test_result_future = 'trf' 307 test_result_future = 'trf'
286 flakiness_algorithm_results_dict = { 308 flakiness_algorithm_results_dict = {
287 'flakes_in_a_row': 4, 309 'flakes_in_a_row': 4,
288 'stable_in_a_row': 0, 310 'stable_in_a_row': 0,
(...skipping 22 matching lines...) Expand all
311 analysis.data_points.append(data_point) 333 analysis.data_points.append(data_point)
312 analysis.put() 334 analysis.put()
313 335
314 NextBuildNumberPipeline.run( 336 NextBuildNumberPipeline.run(
315 NextBuildNumberPipeline(), master_name, builder_name, 337 NextBuildNumberPipeline(), master_name, builder_name,
316 master_build_number, build_number, step_name, 338 master_build_number, build_number, step_name,
317 test_name, analysis.version_number, test_result_future, 339 test_name, analysis.version_number, test_result_future,
318 flakiness_algorithm_results_dict) 340 flakiness_algorithm_results_dict)
319 self.assertEquals(flakiness_algorithm_results_dict['flaked_out'], True) 341 self.assertEquals(flakiness_algorithm_results_dict['flaked_out'], True)
320 342
321 def testNextBuildPipelineForNewRecursionLessThanLastBuildNumber(self): 343 @mock.patch.object(
344 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
345 def testNextBuildPipelineForNewRecursionLessThanLastBuildNumber(
346 self, _mocked_eta_func):
322 master_name = 'm' 347 master_name = 'm'
323 builder_name = 'b' 348 builder_name = 'b'
324 master_build_number = 100 349 master_build_number = 100
325 build_number = 100 350 build_number = 100
326 step_name = 's' 351 step_name = 's'
327 test_name = 't' 352 test_name = 't'
328 test_result_future = 'trf' 353 test_result_future = 'trf'
329 flakiness_algorithm_results_dict = { 354 flakiness_algorithm_results_dict = {
330 'flakes_in_a_row': 0, 355 'flakes_in_a_row': 0,
331 'stable_in_a_row': 0, 356 'stable_in_a_row': 0,
(...skipping 27 matching lines...) Expand all
359 384
360 self.mock( 385 self.mock(
361 recursive_flake_pipeline.RecursiveFlakePipeline, 'start', my_mocked_run) 386 recursive_flake_pipeline.RecursiveFlakePipeline, 'start', my_mocked_run)
362 NextBuildNumberPipeline.run( 387 NextBuildNumberPipeline.run(
363 NextBuildNumberPipeline(), master_name, builder_name, 388 NextBuildNumberPipeline(), master_name, builder_name,
364 master_build_number, build_number, step_name, test_name, 389 master_build_number, build_number, step_name, test_name,
365 analysis.version_number, test_result_future, 390 analysis.version_number, test_result_future,
366 flakiness_algorithm_results_dict) 391 flakiness_algorithm_results_dict)
367 self.assertFalse(queue_name['x']) 392 self.assertFalse(queue_name['x'])
368 393
369 def testNextBuildPipelineForFailedSwarmingTask(self): 394 @mock.patch.object(
395 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
396 def testNextBuildPipelineForFailedSwarmingTask(self, _mocked_eta_func):
370 master_name = 'm' 397 master_name = 'm'
371 builder_name = 'b' 398 builder_name = 'b'
372 master_build_number = 100 399 master_build_number = 100
373 build_number = 100 400 build_number = 100
374 step_name = 's' 401 step_name = 's'
375 test_name = 't' 402 test_name = 't'
376 test_result_future = 'trf' 403 test_result_future = 'trf'
377 flakiness_algorithm_results_dict = { 404 flakiness_algorithm_results_dict = {
378 'flakes_in_a_row': 0, 405 'flakes_in_a_row': 0,
379 'stable_in_a_row': 0, 406 'stable_in_a_row': 0,
(...skipping 27 matching lines...) Expand all
407 queue_name['x'] = True # pragma: no cover 434 queue_name['x'] = True # pragma: no cover
408 435
409 self.mock( 436 self.mock(
410 recursive_flake_pipeline.RecursiveFlakePipeline, 'start', my_mocked_run) 437 recursive_flake_pipeline.RecursiveFlakePipeline, 'start', my_mocked_run)
411 NextBuildNumberPipeline.run( 438 NextBuildNumberPipeline.run(
412 NextBuildNumberPipeline(), master_name, builder_name, 439 NextBuildNumberPipeline(), master_name, builder_name,
413 master_build_number, build_number, step_name, test_name, 1, 440 master_build_number, build_number, step_name, test_name, 1,
414 test_result_future, flakiness_algorithm_results_dict) 441 test_result_future, flakiness_algorithm_results_dict)
415 self.assertFalse(queue_name['x']) 442 self.assertFalse(queue_name['x'])
416 443
417 def testNextBuildPipelineForNewRecursionStabledFlakedOut(self): 444 @mock.patch.object(
445 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
446 def testNextBuildPipelineForNewRecursionStabledFlakedOut(
447 self, _mocked_eta_func):
418 master_name = 'm' 448 master_name = 'm'
419 builder_name = 'b' 449 builder_name = 'b'
420 master_build_number = 100 450 master_build_number = 100
421 build_number = 100 451 build_number = 100
422 step_name = 's' 452 step_name = 's'
423 test_name = 't' 453 test_name = 't'
424 test_result_future = 'trf' 454 test_result_future = 'trf'
425 queue_name = constants.DEFAULT_QUEUE 455 queue_name = constants.DEFAULT_QUEUE
426 flakiness_algorithm_results_dict = { 456 flakiness_algorithm_results_dict = {
427 'flakes_in_a_row': 4, 457 'flakes_in_a_row': 4,
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 'last_build_number': 0, 688 'last_build_number': 0,
659 'lower_boundary': 100, 689 'lower_boundary': 100,
660 'upper_boundary': 110, 690 'upper_boundary': 110,
661 'lower_boundary_result': 'STABLE', 691 'lower_boundary_result': 'STABLE',
662 'sequential_run_index': 1 692 'sequential_run_index': 1
663 } 693 }
664 next_run = sequential_next_run(analysis, flakiness_algorithm_results_dict) 694 next_run = sequential_next_run(analysis, flakiness_algorithm_results_dict)
665 self.assertEqual(next_run, 102) 695 self.assertEqual(next_run, 102)
666 self.assertEqual(analysis.suspected_flake_build_number, None) 696 self.assertEqual(analysis.suspected_flake_build_number, None)
667 697
668 def testNextBuildPipelineStabledOutFlakedOutFirstTime(self): 698 @mock.patch.object(
699 recursive_flake_pipeline, '_GetETAToStartAnalysis', return_value=None)
700 def testNextBuildPipelineStabledOutFlakedOutFirstTime(self, _mocked_eta_func):
669 master_name = 'm' 701 master_name = 'm'
670 builder_name = 'b' 702 builder_name = 'b'
671 master_build_number = 100 703 master_build_number = 100
672 build_number = 100 704 build_number = 100
673 step_name = 's' 705 step_name = 's'
674 test_name = 't' 706 test_name = 't'
675 test_result_future = 'trf' 707 test_result_future = 'trf'
676 flakiness_algorithm_results_dict = { 708 flakiness_algorithm_results_dict = {
677 'flakes_in_a_row': 0, 709 'flakes_in_a_row': 0,
678 'stable_in_a_row': 0, 710 'stable_in_a_row': 0,
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 pipeline = NextBuildNumberPipeline() 866 pipeline = NextBuildNumberPipeline()
835 pipeline.run( 867 pipeline.run(
836 master_name, builder_name, 868 master_name, builder_name,
837 master_build_number, build_number, step_name, test_name, 869 master_build_number, build_number, step_name, test_name,
838 analysis.version_number, test_result_future, 870 analysis.version_number, test_result_future,
839 flakiness_algorithm_results_dict) 871 flakiness_algorithm_results_dict)
840 872
841 analysis = MasterFlakeAnalysis.GetVersion( 873 analysis = MasterFlakeAnalysis.GetVersion(
842 master_name, builder_name, master_build_number, step_name, test_name) 874 master_name, builder_name, master_build_number, step_name, test_name)
843 self.assertEqual(analysis_status.COMPLETED, analysis.status) 875 self.assertEqual(analysis_status.COMPLETED, analysis.status)
OLDNEW
« no previous file with comments | « appengine/findit/waterfall/flake/recursive_flake_pipeline.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698