Beispiel #1
0
    def test_single_phase(self):
        project = self.create_project()
        plan = self.create_plan()

        option = ItemOption(
            item_id=plan.id,
            name='build.expect-tests',
            value='0',
        )
        db.session.add(option)
        db.session.commit()

        build = self.create_build(project=project)
        job = self.create_job(build=build)
        jobphase = self.create_jobphase(
            job=job,
            date_started=datetime(2013, 9, 19, 22, 15, 24),
        )
        jobstep = self.create_jobstep(jobphase)
        jobstep2 = self.create_jobstep(jobphase)

        assert not is_missing_tests(plan, jobstep)

        option.value = '1'
        db.session.commit()

        assert is_missing_tests(plan, jobstep)

        testcase = TestCase(
            project_id=project.id,
            job_id=job.id,
            step_id=jobstep2.id,
            name='test',
        )
        db.session.add(testcase)
        db.session.commit()

        assert is_missing_tests(plan, jobstep)

        testcase = TestCase(
            project_id=project.id,
            job_id=job.id,
            step_id=jobstep.id,
            name='test2',
        )
        db.session.add(testcase)
        db.session.commit()

        assert not is_missing_tests(plan, jobstep)
    def test_missing_test_results_and_expected(self, get_implementation,
                                               queue_delay):
        # Simulate test type which doesn't interact with artifacts store.
        responses.add(responses.GET,
                      SyncJobStepTest.ARTIFACTSTORE_REQUEST_RE,
                      body='',
                      status=404)

        implementation = mock.Mock()
        get_implementation.return_value = implementation

        def mark_finished(step):
            step.status = Status.finished
            step.result = Result.passed

        implementation.update_step.side_effect = mark_finished

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)

        plan = self.create_plan(project)
        self.create_step(plan, implementation='test', order=0)

        db.session.add(
            ItemOption(item_id=plan.id, name='build.expect-tests', value='1'))
        db.session.commit()

        self.create_job_plan(job, plan)

        phase = self.create_jobphase(
            job=job,
            date_started=datetime(2013, 9, 19, 22, 15, 24),
        )
        step = self.create_jobstep(phase)

        with mock.patch.object(sync_job_step, 'allow_absent_from_db', True):
            sync_job_step(
                step_id=step.id.hex,
                task_id=step.id.hex,
                parent_task_id=job.id.hex,
            )

        db.session.expire(step)

        step = JobStep.query.get(step.id)

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

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

        assert FailureReason.query.filter(
            FailureReason.step_id == step.id,
            FailureReason.reason == 'missing_tests',
        )
    def test_snapshot_build(self):
        """
        Test that a snapshot build is not missing tests, even if
        there are no test results reported from the jobstep.
        """
        project = self.create_project()
        plan = self.create_plan(project)

        option = ItemOption(
            item_id=plan.id,
            name='build.expect-tests',
            value='1',
        )
        db.session.add(option)
        db.session.commit()

        build = self.create_build(project=project)
        job = self.create_job(build=build)
        jobplan = self.create_job_plan(job, plan)
        jobphase = self.create_jobphase(
            job=job,
            date_started=datetime(2013, 9, 19, 22, 15, 24),
        )
        jobstep = self.create_jobstep(jobphase)

        assert is_missing_tests(jobstep, jobplan)
        snapshot = self.create_snapshot(project)
        snapshot_image = self.create_snapshot_image(snapshot,
                                                    plan,
                                                    job_id=job.id)
        assert not is_missing_tests(jobstep, jobplan)
    def test_snapshot(self):
        project = self.create_project()
        plan = self.create_plan(project)
        step = self.create_step(plan)

        option = ItemOption(
            item_id=step.id,
            name='build.timeout',
            value='5',
        )
        db.session.add(option)
        db.session.flush()

        build = self.create_build(project=project)
        job = self.create_job(build=build, status=Status.in_progress)
        jobplan = self.create_job_plan(job, plan)

        db.session.commit()

        jobphase = self.create_jobphase(job)
        jobstep = self.create_jobstep(
            jobphase,
            status=Status.in_progress,
            date_started=datetime.utcnow() -
            timedelta(minutes=4 + _SNAPSHOT_TIMEOUT_BONUS_MINUTES))

        with patch('changes.jobs.sync_job_step._is_snapshot_job',
                   return_value=False):
            assert has_timed_out(jobstep, jobplan, 0)

        with patch('changes.jobs.sync_job_step._is_snapshot_job',
                   return_value=True):
            assert not has_timed_out(jobstep, jobplan, 0)
Beispiel #5
0
    def test_simple(self):
        project = self.project
        plan = self.create_plan()
        plan.projects.append(project)
        build = self.create_build(project)
        job = self.create_job(build)
        self.create_job_plan(job, plan)

        db.session.add(
            ItemOption(
                item_id=plan.id,
                name='mail.notify-author',
                value='0',
            ))

        db.session.add(
            ProjectOption(
                project_id=project.id,
                name='mail.notify-author',
                value='1',
            ))

        db.session.add(
            ProjectOption(
                project_id=project.id,
                name='mail.notify-addresses',
                value='*****@*****.**',
            ))
        db.session.commit()

        handler = MailNotificationHandler()
        assert handler.get_job_options(job) == {
            'mail.notify-addresses': '*****@*****.**',
            'mail.notify-author': '0',
        }
Beispiel #6
0
    def test_simple(self):
        project = self.create_project()
        plan = self.create_plan()
        plan.projects.append(project)
        step = self.create_step(plan)

        build = self.create_build(project=project)
        job = self.create_job(build=build, status=Status.queued)
        self.create_job_plan(job, plan)

        option = ItemOption(
            item_id=step.id,
            name='build.timeout',
            value='5',
        )
        db.session.add(option)
        db.session.commit()

        jobphase = self.create_jobphase(job)
        jobstep = self.create_jobstep(jobphase)

        assert not has_timed_out(jobstep, plan)

        jobstep.status = Status.in_progress
        jobstep.date_started = datetime.utcnow()
        db.session.add(jobstep)
        db.session.commit()

        assert not has_timed_out(jobstep, plan)

        jobstep.date_started = datetime.utcnow() - timedelta(seconds=400)
        db.session.add(jobstep)
        db.session.commit()

        assert has_timed_out(jobstep, plan)

        option.value = '0'
        db.session.add(option)
        db.session.commit()

        assert not has_timed_out(jobstep, plan)

        option.value = '500'
        db.session.add(option)
        db.session.commit()

        assert not has_timed_out(jobstep, plan)
Beispiel #7
0
    def test_multi_phase(self):
        project = self.create_project()

        plan = self.create_plan()

        option = ItemOption(
            item_id=plan.id,
            name='build.expect-tests',
            value='1',
        )
        db.session.add(option)
        db.session.commit()

        build = self.create_build(project=project)
        job = self.create_job(build=build)
        jobplan = self.create_job_plan(job, plan)
        jobphase = self.create_jobphase(
            job=job,
            label='setup',
            # it's important that the date_created here is actually newer
            # than the second phase
            date_created=datetime(2013, 9, 19, 22, 17, 24),
            date_started=datetime(2013, 9, 19, 22, 15, 24),
        )
        jobphase2 = self.create_jobphase(
            job=job,
            label='test',
            date_created=datetime(2013, 9, 19, 22, 16, 24),
            date_started=datetime(2013, 9, 19, 22, 16, 24),
        )
        jobstep = self.create_jobstep(jobphase)
        jobstep2 = self.create_jobstep(jobphase2)

        assert not is_missing_tests(jobstep, jobplan)
        assert is_missing_tests(jobstep2, jobplan)

        testcase = TestCase(
            project_id=project.id,
            job_id=job.id,
            step_id=jobstep.id,
            name='test',
        )
        db.session.add(testcase)
        db.session.commit()

        assert not is_missing_tests(jobstep, jobplan)
        assert is_missing_tests(jobstep2, jobplan)

        testcase = TestCase(
            project_id=project.id,
            job_id=job.id,
            step_id=jobstep2.id,
            name='test2',
        )
        db.session.add(testcase)
        db.session.commit()

        assert not is_missing_tests(jobstep2, jobplan)
Beispiel #8
0
    def test_missing_test_results_and_expected(self, get_implementation,
                                               queue_delay):
        implementation = mock.Mock()
        get_implementation.return_value = implementation

        def mark_finished(step):
            step.status = Status.finished
            step.result = Result.passed

        implementation.update_step.side_effect = mark_finished

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)

        plan = self.create_plan()
        self.create_step(plan, implementation='test', order=0)

        db.session.add(
            ItemOption(item_id=plan.id, name='build.expect-tests', value='1'))
        db.session.commit()

        self.create_job_plan(job, plan)

        phase = self.create_jobphase(
            job=job,
            date_started=datetime(2013, 9, 19, 22, 15, 24),
        )
        step = self.create_jobstep(phase)

        sync_job_step(
            step_id=step.id.hex,
            task_id=step.id.hex,
            parent_task_id=job.id.hex,
        )

        db.session.expire(step)

        step = JobStep.query.get(step.id)

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

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

        assert FailureReason.query.filter(
            FailureReason.step_id == step.id,
            FailureReason.reason == 'missing_tests',
        )
Beispiel #9
0
    def test_single_phase(self):
        project = self.create_project()
        plan = self.create_plan()

        option = ItemOption(
            item_id=plan.id,
            name='build.expect-tests',
            value='0',
        )
        db.session.add(option)
        db.session.commit()

        build = self.create_build(project=project)
        job = self.create_job(build=build)
        jobplan = self.create_job_plan(job, plan)
        jobphase = self.create_jobphase(
            job=job,
            date_started=datetime(2013, 9, 19, 22, 15, 24),
        )
        jobstep = self.create_jobstep(jobphase)
        jobstep2 = self.create_jobstep(jobphase)

        assert not is_missing_tests(jobstep, jobplan)

        jobplan.data['snapshot']['options'][option.name] = '1'
        db.session.add(jobplan)
        db.session.commit()

        assert is_missing_tests(jobstep, jobplan)

        testcase = TestCase(
            project_id=project.id,
            job_id=job.id,
            step_id=jobstep2.id,
            name='test',
        )
        db.session.add(testcase)
        db.session.commit()

        assert is_missing_tests(jobstep, jobplan)

        testcase = TestCase(
            project_id=project.id,
            job_id=job.id,
            step_id=jobstep.id,
            name='test2',
        )
        db.session.add(testcase)
        db.session.commit()

        assert not is_missing_tests(jobstep, jobplan)
Beispiel #10
0
    def test_simple(self):
        project = self.create_project()
        plan = self.create_plan(project)
        step = self.create_step(plan)

        option = ItemOption(
            item_id=step.id,
            name='build.timeout',
            value='5',
        )
        db.session.add(option)
        db.session.flush()

        build = self.create_build(project=project)
        job = self.create_job(build=build, status=Status.queued)
        jobplan = self.create_job_plan(job, plan)

        db.session.commit()

        jobphase = self.create_jobphase(job)
        jobstep = self.create_jobstep(jobphase)

        assert not has_timed_out(jobstep, jobplan)

        jobstep.status = Status.in_progress
        jobstep.date_started = datetime.utcnow()
        db.session.add(jobstep)
        db.session.commit()

        assert not has_timed_out(jobstep, jobplan)

        jobstep.date_started = datetime.utcnow() - timedelta(seconds=400)
        db.session.add(jobstep)
        db.session.commit()

        assert has_timed_out(jobstep, jobplan)

        jobplan.data['snapshot']['steps'][0]['options'][option.name] = '0'
        db.session.add(jobplan)
        db.session.commit()

        assert not has_timed_out(jobstep, jobplan)

        jobplan.data['snapshot']['steps'][0]['options'][option.name] = '500'
        db.session.add(jobplan)
        db.session.commit()

        assert not has_timed_out(jobstep, jobplan)
Beispiel #11
0
    def test_simple(self):
        project = self.create_project()
        plan = self.create_plan(project)

        path = '/api/0/plans/{0}/options/'.format(plan.id.hex)

        resp = self.client.get(path)
        assert resp.status_code == 200
        data = self.unserialize(resp)
        assert data['build.expect-tests'] == '0'

        db.session.add(ItemOption(
            name='build.expect-tests',
            value='1',
            item_id=plan.id,
        ))
        db.session.commit()

        resp = self.client.get(path)
        assert resp.status_code == 200
        data = self.unserialize(resp)
        assert data['build.expect-tests'] == '1'
Beispiel #12
0
    def test_simple(self):
        project = self.create_project()
        plan = self.create_plan(project)
        step = self.create_step(plan)

        option = ItemOption(
            item_id=step.id,
            name='build.timeout',
            value='5',
        )
        db.session.add(option)
        db.session.flush()

        build = self.create_build(project=project)
        job = self.create_job(build=build, status=Status.queued)
        jobplan = self.create_job_plan(job, plan)

        db.session.commit()

        # for use as defaults, an instant timeout and one 1k+ years in the future.
        default_always, default_never = 0, 1e9

        jobphase = self.create_jobphase(job)
        jobstep = self.create_jobstep(jobphase)

        assert not has_timed_out(jobstep, jobplan, default_always)

        jobstep.status = Status.allocated
        jobstep.date_created = datetime.utcnow() - timedelta(minutes=6)
        db.session.add(jobstep)
        db.session.commit()

        # No date_started, but based on config value of 5 and date_created from
        # 6 minutes ago, should time out.
        assert has_timed_out(jobstep, jobplan, default_never)

        jobstep.status = Status.in_progress
        jobstep.date_started = datetime.utcnow()
        db.session.add(jobstep)
        db.session.commit()

        # Now we have a recent date_started, shouldn't time out.
        assert not has_timed_out(jobstep, jobplan, default_always)

        # make it so the job started 6 minutes ago.
        jobstep.date_started = datetime.utcnow() - timedelta(minutes=6)
        db.session.add(jobstep)
        db.session.commit()

        # Based on config value of 5, should time out.
        assert has_timed_out(jobstep, jobplan, default_never)

        jobstep.status = Status.allocated
        db.session.add(jobstep)
        db.session.commit()

        # Doesn't require 'in_progress' to time out.
        assert has_timed_out(jobstep, jobplan, default_never)

        jobplan.data['snapshot']['steps'][0]['options'][option.name] = '0'
        db.session.add(jobplan)
        db.session.commit()

        # The timeout option is unset, so default is used.
        assert has_timed_out(jobstep, jobplan, 4)
        assert not has_timed_out(jobstep, jobplan, 7)

        # Make sure we don't ignore 0 as default like we do with the option.
        assert has_timed_out(jobstep, jobplan, 0)

        jobplan.data['snapshot']['steps'][0]['options'][option.name] = '7'
        db.session.add(jobplan)
        db.session.commit()

        assert not has_timed_out(jobstep, jobplan, default_always)
Beispiel #13
0
 def create_option(self, **kwargs):
     option = ItemOption(**kwargs)
     db.session.add(option)
     db.session.commit()
     return option