Пример #1
0
    def test_finished(self, publish_job_update, get_implementation, queue_delay):
        implementation = mock.Mock()
        get_implementation.return_value = implementation

        assert self.jobplan

        build, job, task = self.build, self.job, self.task

        step = job.phases[0].steps[0]

        self.create_task(
            task_name='sync_job_step',
            task_id=step.id,
            parent_id=job.id,
            status=Status.finished,
        )
        self.create_test(job)
        self.create_test(job)

        db.session.add(ItemStat(item_id=step.id, name='tests_missing', value=1))
        db.session.commit()

        sync_job(
            job_id=job.id.hex,
            task_id=job.id.hex,
            parent_task_id=build.id.hex,
        )

        job = Job.query.get(job.id)

        assert job.status == Status.finished

        publish_job_update.assert_called_once_with(job)

        queue_delay.assert_any_call('update_project_plan_stats', kwargs={
            'project_id': self.project.id.hex,
            'plan_id': self.plan.id.hex,
        }, countdown=1)

        queue_delay.assert_any_call('notify_job_finished', kwargs={
            'job_id': job.id.hex,
        })

        task = Task.query.get(task.id)

        assert task.status == Status.finished

        stat = ItemStat.query.filter(
            ItemStat.item_id == job.id,
            ItemStat.name == 'tests_missing',
        ).first()
        assert stat.value == 1
Пример #2
0
    def test_timed_out(self, get_implementation,
                       queue_delay, mock_has_timed_out):
        implementation = mock.Mock()
        get_implementation.return_value = implementation

        build, job, task = self.build, self.job, self.task

        other_build = self.create_build(self.project, status=Status.in_progress)
        other_job = self.create_job(other_build)
        other_jobphase = self.create_jobphase(other_job)
        other_jobstep = self.create_jobstep(other_jobphase)

        mock_has_timed_out.return_value = True

        sync_job(
            job_id=job.id.hex,
            task_id=job.id.hex,
            parent_task_id=build.id.hex
        )

        mock_has_timed_out.assert_called_once_with(job, self.jobplan)

        get_implementation.assert_called_once_with()
        implementation.cancel.assert_called_once_with(
            job=self.job,
        )

        assert job.result == Result.failed
        assert job.status == Status.finished

        assert self.jobphase.result == job.result
        assert self.jobphase.status == job.status

        assert self.jobstep.result == job.result
        assert self.jobstep.status == job.status

        assert FailureReason.query.filter(
            FailureReason.step_id == self.jobstep.id,
            FailureReason.reason == 'timeout',
        )

        # ensure we haven't updated an incorrect jobstep as well
        assert other_jobstep.status == Status.in_progress
        assert other_jobphase.status == Status.in_progress
        assert other_job.status == Status.in_progress
        assert other_build.status == Status.in_progress
Пример #3
0
    def test_in_progress(self, get_implementation,
                         queue_delay):
        implementation = mock.Mock()
        get_implementation.return_value = implementation

        build, job, task = self.build, self.job, self.task

        self.create_task(
            task_name='sync_job_step',
            task_id=job.phases[0].steps[0].id,
            parent_id=job.id,
            status=Status.in_progress,
        )

        def mark_in_progress(job):
            job.status = Status.in_progress

        implementation.update.side_effect = mark_in_progress

        sync_job(
            job_id=job.id.hex,
            task_id=job.id.hex,
            parent_task_id=build.id.hex
        )

        get_implementation.assert_called_once_with()

        implementation.update.assert_called_once_with(
            job=self.job,
        )

        assert implementation.validate_phase.call_count == 0
        assert implementation.validate.call_count == 0

        queue_delay.assert_any_call('sync_job', kwargs={
            'job_id': job.id.hex,
            'task_id': job.id.hex,
            'parent_task_id': build.id.hex,
        }, countdown=5)

        task = Task.query.get(task.id)

        assert task.status == Status.in_progress
Пример #4
0
    def test_finished(self, publish_job_update, get_implementation, queue_delay):
        implementation = mock.Mock()
        get_implementation.return_value = implementation

        assert self.jobplan

        build, job, task = self.build, self.job, self.task

        self.create_task(
            task_name='sync_job_step',
            task_id=job.phases[0].steps[0].id,
            parent_id=job.id,
            status=Status.finished,
        )
        self.create_test(job)
        self.create_test(job)

        sync_job(
            job_id=job.id.hex,
            task_id=job.id.hex,
            parent_task_id=build.id.hex,
        )

        job = Job.query.get(job.id)

        assert job.status == Status.finished

        publish_job_update.assert_called_once_with(job)

        queue_delay.assert_any_call('update_project_plan_stats', kwargs={
            'project_id': self.project.id.hex,
            'plan_id': self.plan.id.hex,
        }, countdown=1)

        queue_delay.assert_any_call('notify_job_finished', kwargs={
            'job_id': job.id.hex,
        })

        task = Task.query.get(task.id)

        assert task.status == Status.finished
Пример #5
0
    def test_finished(self, get_implementation, queue_delay,
                      mock_fire_signal):
        implementation = mock.Mock()
        get_implementation.return_value = implementation

        assert self.jobplan

        build, job, task = self.build, self.job, self.task

        step = job.phases[0].steps[0]

        self.create_task(
            task_name='sync_job_step',
            task_id=step.id,
            parent_id=job.id,
            status=Status.finished,
        )
        self.create_test(job)
        self.create_test(job)

        step2 = self.create_jobstep(self.jobphase, status=Status.finished,
                                    replacement_id=step.id)

        self.jobstep.status = Status.finished
        db.session.add(self.jobstep)

        db.session.add(ItemStat(item_id=step.id, name='tests_missing', value=1))
        db.session.add(ItemStat(item_id=step.id, name='lines_covered', value=10))
        db.session.add(ItemStat(item_id=step.id, name='lines_uncovered', value=25))
        # this shouldn't affect aggregated stats since this jobstep is replaced
        db.session.add(ItemStat(item_id=step2.id, name='lines_uncovered', value=10))
        db.session.commit()

        sync_job(
            job_id=job.id.hex,
            task_id=job.id.hex,
            parent_task_id=build.id.hex,
        )

        implementation.validate_phase.assert_called_once_with(phase=self.job.phases[0])
        implementation.validate.assert_called_once_with(job=self.job)

        job = Job.query.get(job.id)

        assert job.status == Status.finished

        queue_delay.assert_any_call('update_project_plan_stats', kwargs={
            'project_id': self.project.id.hex,
            'plan_id': self.plan.id.hex,
        }, countdown=1)

        mock_fire_signal.delay.assert_any_call(
            signal='job.finished',
            kwargs={'job_id': job.id.hex},
        )

        task = Task.query.get(task.id)

        assert task.status == Status.finished

        stat = ItemStat.query.filter(
            ItemStat.item_id == job.id,
            ItemStat.name == 'tests_missing',
        ).first()
        assert stat.value == 1

        stat = ItemStat.query.filter(
            ItemStat.item_id == job.id,
            ItemStat.name == 'lines_covered',
        ).first()
        assert stat.value == 10

        stat = ItemStat.query.filter(
            ItemStat.item_id == job.id,
            ItemStat.name == 'lines_uncovered',
        ).first()
        assert stat.value == 25