Chromium Code Reviews| 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 import datetime | |
| 6 | |
| 5 from common.git_repository import GitRepository | 7 from common.git_repository import GitRepository |
| 6 from common.rietveld import Rietveld | 8 from common.rietveld import Rietveld |
| 7 from model import analysis_status as status | 9 from model import analysis_status as status |
| 8 from model.wf_culprit import WfCulprit | 10 from model.wf_culprit import WfCulprit |
| 9 from waterfall import send_notification_for_culprit_pipeline | 11 from waterfall import send_notification_for_culprit_pipeline |
| 10 from waterfall.send_notification_for_culprit_pipeline import ( | 12 from waterfall.send_notification_for_culprit_pipeline import ( |
| 11 SendNotificationForCulpritPipeline) | 13 SendNotificationForCulpritPipeline) |
| 12 from waterfall.test import wf_testcase | 14 from waterfall.test import wf_testcase |
| 13 | 15 |
| 14 | 16 |
| 17 _MOCKED_DATETIME_UTCNOW = datetime.datetime(2016, 06, 28, 12, 44, 00) | |
| 18 _MOCKED_COMMIT_TIME = datetime.datetime(2016, 06, 28, 12, 40, 00) | |
| 19 | |
| 15 class SendNotificationForCulpritPipelineTest(wf_testcase.WaterfallTestCase): | 20 class SendNotificationForCulpritPipelineTest(wf_testcase.WaterfallTestCase): |
| 16 | 21 |
| 17 def _MockRietveldAndGitRepository(self, mocked_url, rietveld_requests): | 22 def _MockRietveld(self, rietveld_requests): |
| 23 def Mocked_Rietveld_PostMessage(_, url, message): | |
| 24 rietveld_requests.append((url, message)) | |
| 25 return True | |
| 26 self.mock(Rietveld, 'PostMessage', Mocked_Rietveld_PostMessage) | |
| 27 | |
| 28 def _MockGitRepository(self, mocked_url): | |
| 18 def Mocked_GetChangeLog(*_): | 29 def Mocked_GetChangeLog(*_): |
| 19 class MockedChangeLog(object): | 30 class MockedChangeLog(object): |
| 20 @property | 31 @property |
| 21 def code_review_url(self): | 32 def code_review_url(self): |
| 22 return mocked_url | 33 return mocked_url |
| 34 @property | |
| 35 def committer_time(self): | |
| 36 return _MOCKED_COMMIT_TIME | |
| 23 return MockedChangeLog() | 37 return MockedChangeLog() |
| 24 self.mock(GitRepository, 'GetChangeLog', Mocked_GetChangeLog) | 38 self.mock(GitRepository, 'GetChangeLog', Mocked_GetChangeLog) |
| 25 def Mocked_Rietveld_PostMessage(_, url, message): | 39 |
| 26 rietveld_requests.append((url, message)) | 40 def _MockDatetimeUtcNow(self, mocked_utcnow): |
|
chanli
2016/06/30 20:23:42
This should be trivial: I noticed that for all _Mo
stgao
2016/06/30 22:37:45
Done.
| |
| 27 return True | 41 class Mocked_Datetime(object): |
| 28 self.mock(Rietveld, 'PostMessage', Mocked_Rietveld_PostMessage) | 42 @staticmethod |
| 43 def utcnow(): | |
| 44 return mocked_utcnow | |
| 45 self.mock(send_notification_for_culprit_pipeline, | |
| 46 'datetime', Mocked_Datetime) | |
| 29 | 47 |
| 30 def testShouldNotSendNotificationForSingleFailedBuild(self): | 48 def testShouldNotSendNotificationForSingleFailedBuild(self): |
| 31 self.assertFalse( | 49 self.assertFalse( |
| 32 send_notification_for_culprit_pipeline._ShouldSendNotification( | 50 send_notification_for_culprit_pipeline._ShouldSendNotification( |
| 33 'm', 'b1', 1, 'chromium', 'r1')) | 51 'm', 'b1', 1, 'chromium', 'r1', 2, False)) |
| 34 culprit = WfCulprit.Get('chromium', 'r1') | 52 culprit = WfCulprit.Get('chromium', 'r1') |
| 35 self.assertIsNotNone(culprit) | 53 self.assertIsNotNone(culprit) |
| 36 self.assertEqual([['m', 'b1', 1]], culprit.builds) | 54 self.assertEqual([['m', 'b1', 1]], culprit.builds) |
| 37 | 55 |
| 38 def testShouldNotSendNotificationForSameFailedBuild(self): | 56 def testShouldNotSendNotificationForSameFailedBuild(self): |
| 39 self.assertFalse( | 57 self.assertFalse( |
| 40 send_notification_for_culprit_pipeline._ShouldSendNotification( | 58 send_notification_for_culprit_pipeline._ShouldSendNotification( |
| 41 'm', 'b2', 2, 'chromium', 'r2')) | 59 'm', 'b2', 2, 'chromium', 'r2', 2, False)) |
| 42 self.assertFalse( | 60 self.assertFalse( |
| 43 send_notification_for_culprit_pipeline._ShouldSendNotification( | 61 send_notification_for_culprit_pipeline._ShouldSendNotification( |
| 44 'm', 'b2', 2, 'chromium', 'r2')) | 62 'm', 'b2', 2, 'chromium', 'r2', 2, False)) |
| 45 culprit = WfCulprit.Get('chromium', 'r2') | 63 culprit = WfCulprit.Get('chromium', 'r2') |
| 46 self.assertIsNotNone(culprit) | 64 self.assertIsNotNone(culprit) |
| 47 self.assertEqual([['m', 'b2', 2]], culprit.builds) | 65 self.assertEqual([['m', 'b2', 2]], culprit.builds) |
| 48 | 66 |
| 49 def testShouldSendNotificationForSecondFailedBuild(self): | 67 def testShouldSendNotificationForSecondFailedBuild(self): |
| 50 self.assertFalse( | 68 self.assertFalse( |
| 51 send_notification_for_culprit_pipeline._ShouldSendNotification( | 69 send_notification_for_culprit_pipeline._ShouldSendNotification( |
| 52 'm', 'b31', 31, 'chromium', 'r3')) | 70 'm', 'b31', 31, 'chromium', 'r3', 2, False)) |
| 53 self.assertTrue( | 71 self.assertTrue( |
| 54 send_notification_for_culprit_pipeline._ShouldSendNotification( | 72 send_notification_for_culprit_pipeline._ShouldSendNotification( |
| 55 'm', 'b32', 32, 'chromium', 'r3')) | 73 'm', 'b32', 32, 'chromium', 'r3', 2, False)) |
| 56 culprit = WfCulprit.Get('chromium', 'r3') | 74 culprit = WfCulprit.Get('chromium', 'r3') |
| 57 self.assertIsNotNone(culprit) | 75 self.assertIsNotNone(culprit) |
| 58 self.assertEqual(status.RUNNING, culprit.cr_notification_status) | 76 self.assertEqual(status.RUNNING, culprit.cr_notification_status) |
| 59 self.assertEqual([['m', 'b31', 31], ['m', 'b32', 32]], culprit.builds) | 77 self.assertEqual([['m', 'b31', 31], ['m', 'b32', 32]], culprit.builds) |
| 60 | 78 |
| 61 def testShouldNotSendNotificationForFirstFailedBuildCycle(self): | 79 def testShouldNotSendNotificationForFirstFailedBuildCycle(self): |
| 62 rietveld_requests = [] | 80 rietveld_requests = [] |
| 63 self._MockRietveldAndGitRepository('url', rietveld_requests) | 81 self._MockRietveld(rietveld_requests) |
| 82 self._MockGitRepository('url') | |
| 83 self._MockDatetimeUtcNow(_MOCKED_DATETIME_UTCNOW) | |
| 64 | 84 |
| 65 pipeline = SendNotificationForCulpritPipeline() | 85 pipeline = SendNotificationForCulpritPipeline() |
| 66 self.assertFalse(pipeline.run('m', 'b4', 4, 'chromium', 'r4')) | 86 self.assertFalse(pipeline.run('m', 'b4', 4, 'chromium', 'r4')) |
| 67 self.assertEqual(0, len(rietveld_requests)) | 87 self.assertEqual(0, len(rietveld_requests)) |
| 68 | 88 |
| 69 def testShouldNotSendNotificationIfNoCodeReview(self): | 89 def testShouldNotSendNotificationIfNoCodeReview(self): |
| 70 rietveld_requests = [] | 90 rietveld_requests = [] |
| 71 self._MockRietveldAndGitRepository(None, rietveld_requests) | 91 self._MockRietveld(rietveld_requests) |
| 92 self._MockGitRepository(None) | |
| 93 self._MockDatetimeUtcNow(_MOCKED_DATETIME_UTCNOW) | |
| 72 culprit = WfCulprit.Create('chromium', 'r5') | 94 culprit = WfCulprit.Create('chromium', 'r5') |
| 73 culprit.builds.append(['m', 'b51', 51]) | 95 culprit.builds.append(['m', 'b51', 51]) |
| 74 culprit.put() | 96 culprit.put() |
| 75 | 97 |
| 76 pipeline = SendNotificationForCulpritPipeline() | 98 pipeline = SendNotificationForCulpritPipeline() |
| 77 self.assertFalse(pipeline.run('m', 'b52', 52, 'chromium', 'r5')) | 99 self.assertFalse(pipeline.run('m', 'b52', 52, 'chromium', 'r5')) |
| 78 self.assertEqual(0, len(rietveld_requests)) | 100 self.assertEqual(0, len(rietveld_requests)) |
| 79 | 101 |
| 80 def testSendNotificationSuccess(self): | 102 def testSendNotificationSuccess(self): |
| 81 rietveld_requests = [] | 103 rietveld_requests = [] |
| 82 self._MockRietveldAndGitRepository('url', rietveld_requests) | 104 self._MockRietveld(rietveld_requests) |
| 105 self._MockGitRepository('url') | |
| 106 self._MockDatetimeUtcNow(_MOCKED_DATETIME_UTCNOW) | |
| 83 culprit = WfCulprit.Create('chromium', 'r6') | 107 culprit = WfCulprit.Create('chromium', 'r6') |
| 84 culprit.builds.append(['m', 'b61', 61]) | 108 culprit.builds.append(['m', 'b61', 61]) |
| 85 culprit.put() | 109 culprit.put() |
| 86 | 110 |
| 87 pipeline = SendNotificationForCulpritPipeline() | 111 pipeline = SendNotificationForCulpritPipeline() |
| 88 self.assertTrue(pipeline.run('m', 'b62', 62, 'chromium', 'r6')) | 112 self.assertTrue(pipeline.run('m', 'b62', 62, 'chromium', 'r6')) |
| 89 self.assertEqual(1, len(rietveld_requests)) | 113 self.assertEqual(1, len(rietveld_requests)) |
| OLD | NEW |