| 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 datetime import datetime | 5 from datetime import datetime |
| 6 import json | 6 import json |
| 7 import time | 7 import time |
| 8 | 8 |
| 9 from common.waterfall import buildbucket_client |
| 9 from common.waterfall import try_job_error | 10 from common.waterfall import try_job_error |
| 10 from common.waterfall import buildbucket_client | |
| 11 from model import analysis_status | 11 from model import analysis_status |
| 12 from model.wf_try_job import WfTryJob | 12 from model.wf_try_job import WfTryJob |
| 13 from model.wf_try_job_data import WfTryJobData | 13 from model.wf_try_job_data import WfTryJobData |
| 14 from waterfall import waterfall_config | 14 from waterfall import waterfall_config |
| 15 from waterfall.monitor_try_job_pipeline import MonitorTryJobPipeline | 15 from waterfall.monitor_try_job_pipeline import MonitorTryJobPipeline |
| 16 from waterfall.test import wf_testcase | 16 from waterfall.test import wf_testcase |
| 17 from waterfall.try_job_type import TryJobType | 17 from waterfall.try_job_type import TryJobType |
| 18 | 18 |
| 19 | 19 |
| 20 # A counter to enable different responses to requests in a loop. | 20 # A counter to enable different responses to requests in a loop. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 'reason': 'BUILD_NOT_FOUND', | 137 'reason': 'BUILD_NOT_FOUND', |
| 138 'message': 'message' | 138 'message': 'message' |
| 139 } | 139 } |
| 140 error = buildbucket_client.BuildbucketError(error_data) | 140 error = buildbucket_client.BuildbucketError(error_data) |
| 141 try_job_data = WfTryJobData.Create('1') | 141 try_job_data = WfTryJobData.Create('1') |
| 142 | 142 |
| 143 MonitorTryJobPipeline._UpdateTryJobMetadata( | 143 MonitorTryJobPipeline._UpdateTryJobMetadata( |
| 144 try_job_data, None, None, error, False) | 144 try_job_data, None, None, error, False) |
| 145 self.assertEqual(try_job_data.error, error_data) | 145 self.assertEqual(try_job_data.error, error_data) |
| 146 | 146 |
| 147 def testUpdateTryJobMetadataForCompletedBuild(self): | 147 def testUpdateTryJobMetadata(self): |
| 148 try_job_id = '1' | 148 try_job_id = '1' |
| 149 url = 'url' | 149 url = 'url' |
| 150 build_data = { | 150 build_data = { |
| 151 'id': try_job_id, | 151 'id': try_job_id, |
| 152 'url': url, | 152 'url': url, |
| 153 'status': 'COMPLETED', | 153 'status': 'COMPLETED', |
| 154 'completed_ts': '1454367574000000', | 154 'completed_ts': '1454367574000000', |
| 155 'created_ts': '1454367570000000', | 155 'created_ts': '1454367570000000', |
| 156 'result_details_json': json.dumps({ | 156 'result_details_json': json.dumps({ |
| 157 'properties': { | 157 'properties': { |
| 158 'report': { | 158 'report': { |
| 159 'result': { | 159 'result': { |
| 160 'rev1': 'passed', | 160 'rev1': 'passed', |
| 161 'rev2': 'failed' | 161 'rev2': 'failed' |
| 162 }, | 162 }, |
| 163 'metadata': { | 163 'metadata': { |
| 164 'regression_range_size': 2 | 164 'regression_range_size': 2 |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 }) | 168 }) |
| 169 } | 169 } |
| 170 build = buildbucket_client.BuildbucketBuild(build_data) | 170 build = buildbucket_client.BuildbucketBuild(build_data) |
| 171 try_job_data = WfTryJobData.Create(try_job_id) | |
| 172 | |
| 173 expected_error_dict = { | 171 expected_error_dict = { |
| 174 'message': 'Try job monitoring was abandoned.', | 172 'message': 'Try job monitoring was abandoned.', |
| 175 'reason': ('Timeout after %s hours' % | 173 'reason': ('Timeout after %s hours' % |
| 176 waterfall_config.GetTryJobSettings().get( | 174 waterfall_config.GetTryJobSettings().get( |
| 177 'job_timeout_hours')) | 175 'job_timeout_hours')) |
| 178 } | 176 } |
| 177 try_job_data = WfTryJobData.Create(try_job_id) |
| 179 | 178 |
| 180 MonitorTryJobPipeline._UpdateTryJobMetadata( | 179 MonitorTryJobPipeline._UpdateTryJobMetadata( |
| 181 try_job_data, None, build, None, False) | 180 try_job_data, None, build, None, False) |
| 182 try_job_data = WfTryJobData.Get(try_job_id) | 181 try_job_data = WfTryJobData.Get(try_job_id) |
| 183 self.assertIsNone(try_job_data.error) | 182 self.assertIsNone(try_job_data.error) |
| 184 self.assertEqual(try_job_data.regression_range_size, 2) | 183 self.assertEqual(try_job_data.regression_range_size, 2) |
| 185 self.assertEqual(try_job_data.number_of_commits_analyzed, 2) | 184 self.assertEqual(try_job_data.number_of_commits_analyzed, 2) |
| 186 self.assertEqual(try_job_data.end_time, datetime(2016, 2, 1, 22, 59, 34)) | 185 self.assertEqual(try_job_data.end_time, datetime(2016, 2, 1, 22, 59, 34)) |
| 187 self.assertEqual(try_job_data.request_time, | 186 self.assertEqual(try_job_data.request_time, |
| 188 datetime(2016, 2, 1, 22, 59, 30)) | 187 datetime(2016, 2, 1, 22, 59, 30)) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 master_name = 'm' | 245 master_name = 'm' |
| 247 builder_name = 'b' | 246 builder_name = 'b' |
| 248 build_number = 1 | 247 build_number = 1 |
| 249 try_job_id = '3' | 248 try_job_id = '3' |
| 250 | 249 |
| 251 try_job = WfTryJob.Create(master_name, builder_name, build_number) | 250 try_job = WfTryJob.Create(master_name, builder_name, build_number) |
| 252 try_job.test_results = [ | 251 try_job.test_results = [ |
| 253 { | 252 { |
| 254 'report': None, | 253 'report': None, |
| 255 'url': 'url', | 254 'url': 'url', |
| 256 'try_job_id': '3', | 255 'try_job_id': try_job_id, |
| 257 } | 256 } |
| 258 ] | 257 ] |
| 259 try_job.status = analysis_status.RUNNING | 258 try_job.status = analysis_status.RUNNING |
| 260 try_job.put() | 259 try_job.put() |
| 260 |
| 261 try_job_data = WfTryJobData.Create(try_job_id) |
| 262 try_job_data.put() |
| 263 |
| 261 self._MockGetTryJobs(try_job_id) | 264 self._MockGetTryJobs(try_job_id) |
| 262 | 265 |
| 263 pipeline = MonitorTryJobPipeline() | 266 pipeline = MonitorTryJobPipeline() |
| 264 test_result = pipeline.run( | 267 test_result = pipeline.run( |
| 265 master_name, builder_name, build_number, TryJobType.TEST, | 268 master_name, builder_name, build_number, TryJobType.TEST, |
| 266 try_job_id) | 269 try_job_id) |
| 267 | 270 |
| 268 expected_test_result = { | 271 expected_test_result = { |
| 269 'report': { | 272 'report': { |
| 270 'result': { | 273 'result': { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 415 } |
| 413 | 416 |
| 414 expected_error_dict = { | 417 expected_error_dict = { |
| 415 'message': 'No result report was found.', | 418 'message': 'No result report was found.', |
| 416 'reason': MonitorTryJobPipeline.UNKNOWN | 419 'reason': MonitorTryJobPipeline.UNKNOWN |
| 417 } | 420 } |
| 418 | 421 |
| 419 self.assertEqual( | 422 self.assertEqual( |
| 420 MonitorTryJobPipeline._GetError(build_response, None, False), | 423 MonitorTryJobPipeline._GetError(build_response, None, False), |
| 421 (expected_error_dict, try_job_error.UNKNOWN)) | 424 (expected_error_dict, try_job_error.UNKNOWN)) |
| OLD | NEW |