| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 testing_utils import testing | 5 from testing_utils import testing |
| 6 | 6 |
| 7 from common import buildbucket_client | 7 from common import buildbucket_client |
| 8 from model import wf_analysis_status | 8 from model import wf_analysis_status |
| 9 from model.wf_try_job import WfTryJob | 9 from model.wf_try_job import WfTryJob |
| 10 from waterfall.monitor_try_job_pipeline import MonitorTryJobPipeline | 10 from waterfall.monitor_try_job_pipeline import MonitorTryJobPipeline |
| 11 from waterfall.try_job_type import TryJobType |
| 11 | 12 |
| 12 | 13 |
| 13 class MonitorTryJobPipelineTest(testing.AppengineTestCase): | 14 class MonitorTryJobPipelineTest(testing.AppengineTestCase): |
| 14 | 15 |
| 15 def _Mock_GetTryJobs(self, build_id): | 16 def _Mock_GetTryJobs(self, build_id): |
| 16 def Mocked_GetTryJobs(*_): | 17 def Mocked_GetTryJobs(*_): |
| 17 data = { | 18 data = { |
| 18 '1': { | 19 '1': { |
| 19 'build': { | 20 'build': { |
| 20 'id': '1', | 21 'id': '1', |
| 21 'url': 'url', | 22 'url': 'url', |
| 22 'status': 'COMPLETED', | 23 'status': 'COMPLETED', |
| 23 'result_details_json': ( | 24 'result_details_json': ( |
| 24 '{"properties": {"result": [["rev1", "passed"],' | 25 '{"properties": {"result": [["rev1", "passed"],' |
| 25 ' ["rev2", "failed"]]}}') | 26 ' ["rev2", "failed"]]}}') |
| 26 } | 27 } |
| 27 }, | 28 }, |
| 28 '2': { | 29 '2': { |
| 29 'error': { | 30 'error': { |
| 30 'reason': 'BUILD_NOT_FOUND', | 31 'reason': 'BUILD_NOT_FOUND', |
| 31 'message': 'message', | 32 'message': 'message', |
| 32 } | 33 } |
| 34 }, |
| 35 '3': { |
| 36 'build': { |
| 37 'id': '3', |
| 38 'url': 'url', |
| 39 'status': 'COMPLETED', |
| 40 'result_details_json': ( |
| 41 '{"properties": {"result": {"rev1": {"a_test": {"status":' |
| 42 ' "passed", "valid": true}}, "rev2": {"a_test": ' |
| 43 '{"status": "failed", "valid": true, "failures": ["test1"' |
| 44 ', "test2"]}}}}}') |
| 45 } |
| 33 } | 46 } |
| 34 } | 47 } |
| 35 compile_results = [] | 48 try_job_results = [] |
| 36 build_error = data.get(build_id) | 49 build_error = data.get(build_id) |
| 37 if build_error.get('error'): # pragma: no cover | 50 if build_error.get('error'): # pragma: no cover |
| 38 compile_results.append(( | 51 try_job_results.append(( |
| 39 buildbucket_client.BuildbucketError(build_error['error']), None)) | 52 buildbucket_client.BuildbucketError(build_error['error']), None)) |
| 40 else: | 53 else: |
| 41 compile_results.append(( | 54 try_job_results.append(( |
| 42 None, buildbucket_client.BuildbucketBuild(build_error['build']))) | 55 None, buildbucket_client.BuildbucketBuild(build_error['build']))) |
| 43 return compile_results | 56 return try_job_results |
| 44 self.mock(buildbucket_client, 'GetTryJobs', Mocked_GetTryJobs) | 57 self.mock(buildbucket_client, 'GetTryJobs', Mocked_GetTryJobs) |
| 45 | 58 |
| 46 def testGetTryJobsForCompileSuccess(self): | 59 def testGetTryJobsForCompileSuccess(self): |
| 47 master_name = 'm' | 60 master_name = 'm' |
| 48 builder_name = 'b' | 61 builder_name = 'b' |
| 49 build_number = 1 | 62 build_number = 1 |
| 50 try_job_id = '1' | 63 try_job_id = '1' |
| 51 | 64 |
| 52 try_job = WfTryJob.Create(master_name, builder_name, build_number) | 65 try_job = WfTryJob.Create(master_name, builder_name, build_number) |
| 53 try_job.compile_results = [ | 66 try_job.compile_results = [ |
| 54 { | 67 { |
| 55 'report': None, | 68 'report': None, |
| 56 'url': 'url', | 69 'url': 'url', |
| 57 'try_job_id': '1', | 70 'try_job_id': '1', |
| 58 } | 71 } |
| 59 ] | 72 ] |
| 60 try_job.status = wf_analysis_status.ANALYZING | 73 try_job.status = wf_analysis_status.ANALYZING |
| 61 try_job.put() | 74 try_job.put() |
| 62 self._Mock_GetTryJobs(try_job_id) | 75 self._Mock_GetTryJobs(try_job_id) |
| 63 | 76 |
| 64 pipeline = MonitorTryJobPipeline() | 77 pipeline = MonitorTryJobPipeline() |
| 65 compile_result = pipeline.run( | 78 compile_result = pipeline.run( |
| 66 master_name, builder_name, build_number, try_job_id) | 79 master_name, builder_name, build_number, TryJobType.COMPILE, |
| 80 try_job_id) |
| 67 | 81 |
| 68 expected_compile_result = { | 82 expected_compile_result = { |
| 69 'report': [ | 83 'report': [ |
| 70 ['rev1', 'passed'], | 84 ['rev1', 'passed'], |
| 71 ['rev2', 'failed'] | 85 ['rev2', 'failed'] |
| 72 ], | 86 ], |
| 73 'url': 'url', | 87 'url': 'url', |
| 74 'try_job_id': '1', | 88 'try_job_id': '1', |
| 75 } | 89 } |
| 76 self.assertEqual(expected_compile_result, compile_result) | 90 self.assertEqual(expected_compile_result, compile_result) |
| 77 | 91 |
| 78 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 92 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| 79 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) | 93 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) |
| 80 self.assertEqual(wf_analysis_status.ANALYZING, try_job.status) | 94 self.assertEqual(wf_analysis_status.ANALYZING, try_job.status) |
| 95 |
| 96 |
| 97 def testGetTryJobsForTestSuccess(self): |
| 98 master_name = 'm' |
| 99 builder_name = 'b' |
| 100 build_number = 1 |
| 101 try_job_id = '3' |
| 102 |
| 103 try_job = WfTryJob.Create(master_name, builder_name, build_number) |
| 104 try_job.test_results = [ |
| 105 { |
| 106 'report': None, |
| 107 'url': 'url', |
| 108 'try_job_id': '3', |
| 109 } |
| 110 ] |
| 111 try_job.status = wf_analysis_status.ANALYZING |
| 112 try_job.put() |
| 113 self._Mock_GetTryJobs(try_job_id) |
| 114 |
| 115 pipeline = MonitorTryJobPipeline() |
| 116 test_result = pipeline.run( |
| 117 master_name, builder_name, build_number, TryJobType.TEST, |
| 118 try_job_id) |
| 119 |
| 120 expected_test_result = { |
| 121 'report': { |
| 122 'rev1': { |
| 123 'a_test': { |
| 124 'status': 'passed', |
| 125 'valid': True |
| 126 } |
| 127 }, |
| 128 'rev2': { |
| 129 'a_test': { |
| 130 'status': 'failed', |
| 131 'valid': True, |
| 132 'failures': ['test1', 'test2'] |
| 133 } |
| 134 } |
| 135 }, |
| 136 'url': 'url', |
| 137 'try_job_id': '3', |
| 138 } |
| 139 self.assertEqual(expected_test_result, test_result) |
| 140 |
| 141 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| 142 self.assertEqual(expected_test_result, try_job.test_results[-1]) |
| 143 self.assertEqual(wf_analysis_status.ANALYZING, try_job.status) |
| OLD | NEW |