def testCallbackImplNoTryJobID(self, mocked_pipeline_id,
                                mocked_OnTryJobStateChanged):
   mocked_pipeline_id.__get__ = mock.Mock(return_value='pipeline-id')
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   returned_value = p.CallbackImpl(pipeline_input, {'build_json': '{"k":"v"}'})
   self.assertEqual(('Try_job_id not found for pipeline pipeline-id', None),
                    returned_value)
   self.assertFalse(mocked_OnTryJobStateChanged.called)
 def testCallbackImplNotCompletedRun(self, mocked_OnTryJobStateChanged):
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   returned_value = p.CallbackImpl(pipeline_input, {
       'try_job_id': 'job-id',
       'build_json': '{"k":"v"}'
   })
   self.assertIsNone(returned_value)
   mocked_OnTryJobStateChanged.assert_called_once_with('job-id', {'k': 'v'},
                                                       pipeline_input)
 def testRunImplRetryUponFailure(self, mocked_ScheduleCompileTryJob,
                                 mocked_SaveCallbackParameters,
                                 mocked_pipeline_id, _):
   mocked_pipeline_id.__get__ = mock.Mock(return_value='pipeline-id')
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   with self.assertRaises(pipeline.Retry):
     p.RunImpl(pipeline_input)
   mocked_ScheduleCompileTryJob.assert_called_once_with(
       pipeline_input, 'pipeline-id')
   self.assertFalse(mocked_SaveCallbackParameters.called)
 def testCallbackImplFailedRun(self, mocked_OnTryJobStateChanged):
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   returned_value = p.CallbackImpl(pipeline_input, {
       'try_job_id': 'job-id',
       'build_json': '{"k":"v"}'
   })
   self.assertEqual(('Error on updating try-job result: m', None),
                    returned_value)
   mocked_OnTryJobStateChanged.assert_called_once_with('job-id', {'k': 'v'},
                                                       pipeline_input)
 def testRunImplSuccessfulRun(self, mocked_ScheduleCompileTryJob,
                              mocked_SaveCallbackParameters,
                              mocked_pipeline_id, _):
   mocked_pipeline_id.__get__ = mock.Mock(return_value='pipeline-id')
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   p.RunImpl(pipeline_input)
   mocked_ScheduleCompileTryJob.assert_called_once_with(
       pipeline_input, 'pipeline-id')
   mocked_SaveCallbackParameters.assert_called_once_with({
       'try_job_id': 'job_id'
   })
    def RunImpl(self, pipeline_input):
        """Starts a try job if one is needed for the given compile failure."""
        if not pipeline_input.build_completed:
            # Only start try-jobs for completed builds.
            return

        need_try_job, urlsafe_try_job_key = compile_try_job.NeedANewCompileTryJob(
            pipeline_input)
        if not need_try_job:
            return

        parameters = compile_try_job.GetParametersToScheduleCompileTryJob(
            pipeline_input, urlsafe_try_job_key)
        if not parameters.good_revision:
            # No last_pass in saved in failure_info.
            return

        try_job_result = yield RunCompileTryJobPipeline(parameters)

        identify_culprit_input = self.CreateInputObjectInstance(
            IdentifyCompileTryJobCulpritParameters,
            build_key=pipeline_input.build_key,
            result=try_job_result)
        yield culprit_pipeline.IdentifyCompileTryJobCulpritPipeline(
            identify_culprit_input)
 def testRunImplNotTriggerSameJobTwice(self, mocked_ScheduleCompileTryJob, _):
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   p.RunImpl(pipeline_input)
   self.assertFalse(mocked_ScheduleCompileTryJob.called)
 def testOnTimeout(self, mocked_OnTryJobTimeout):
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   p.OnTimeout(pipeline_input, {'try_job_id': 'id'})
   mocked_OnTryJobTimeout.assert_called_once_with('id', pipeline_input)
 def testTimeoutSeconds(self):
   pipeline_input = self._CreateRunCompileTryJobParameters()
   p = RunCompileTryJobPipeline(pipeline_input)
   self.assertEqual(36000, p.TimeoutSeconds())