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_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(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)
    def test_single_phase(self):
        project = self.create_project()
        plan = self.create_plan(project)

        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)
Ejemplo n.º 5
0
    def test_simple(self):
        project = self.create_project()
        plan = self.create_plan(project)
        build = self.create_build(project, result=Result.failed)
        job = self.create_job(build, result=Result.failed)

        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.flush()

        self.create_job_plan(job, plan)

        db.session.commit()

        handler = MailNotificationHandler()
        assert handler.get_build_options(build) == {
            'mail.notify-addresses': {'*****@*****.**'},
            'mail.notify-addresses-revisions': set(),
            'mail.notify-author': False,
        }
Ejemplo n.º 6
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'
Ejemplo n.º 7
0
 def create_option(self, **kwargs):
     option = ItemOption(**kwargs)
     db.session.add(option)
     db.session.commit()
     return option
Ejemplo n.º 8
0
    def test_multiple_jobs(self):
        project = self.create_project()
        build = self.create_build(project, result=Result.failed)
        job1 = self.create_job(build, result=Result.failed)
        job2 = self.create_job(build, result=Result.failed)
        plan1 = self.create_plan(project)
        plan2 = self.create_plan(project)

        # Plan1 options.
        db.session.add(
            ItemOption(
                item_id=plan1.id,
                name='mail.notify-addresses',
                value='*****@*****.**',
            ))
        db.session.add(
            ItemOption(
                item_id=plan1.id,
                name='mail.notify-author',
                value='0',
            ))

        # Plan2 options.
        db.session.add(
            ItemOption(
                item_id=plan2.id,
                name='mail.notify-addresses',
                value='*****@*****.**',
            ))
        db.session.add(
            ItemOption(
                item_id=plan2.id,
                name='mail.notify-author',
                value='1',
            ))

        # Project options (notify-author is set to test that plan options can
        # override it).
        db.session.add(
            ProjectOption(
                project_id=project.id,
                name='mail.notify-author',
                value='0',
            ))

        # Set notify addresses to verify that it is not used when all jobs
        # override it.
        db.session.add(
            ProjectOption(
                project_id=project.id,
                name='mail.notify-addresses',
                value='*****@*****.**',
            ))
        db.session.flush()

        for job, plan in [(job1, plan1), (job2, plan2)]:
            self.create_job_plan(job, plan)

        db.session.commit()

        handler = MailNotificationHandler()
        assert handler.get_build_options(build) == {
            'mail.notify-addresses':
            {'*****@*****.**', '*****@*****.**'},
            'mail.notify-addresses-revisions': set(),
            'mail.notify-author': True,
        }
    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()

        # Jobstep has only been allocated, not started just yet.
        # Timeout for jobsteps in queue applied, shouldn't time out.
        assert not 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)

        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)
    def test_multi_phase(self):
        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,
            label='setup',
            date_created=datetime(2013, 9, 19, 22, 15, 24),
        )
        jobphase2 = self.create_jobphase(
            job=job,
            label='test',
            date_created=datetime(2013, 9, 19, 22, 16, 24),
        )
        jobstep = self.create_jobstep(jobphase)
        jobstep2 = self.create_jobstep(jobphase2)

        job2 = self.create_job(build=build)
        self.create_job_plan(job2, plan)
        # this has a later date_created than jobphase2, but shouldn't be
        # considered because it's a different job.
        self.create_jobphase(
            job=job2,
            label='differentjob',
            date_created=datetime(2013, 9, 19, 22, 17, 24),
        )

        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)
    def test_non_running(self):
        # Verify separate timeout for non-running jobsteps
        default_never = 1e9

        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)

        jobphase = self.create_jobphase(job)

        jobstep = self.create_jobstep(jobphase)
        jobstep.status = Status.pending_allocation
        jobstep.date_created = datetime.utcnow() - timedelta(minutes=6)

        db.session.add(jobstep)
        db.session.commit()

        # Jobstep is still pending allocation.
        # Timeout for jobsteps in queue applied, shouldn't time out.
        assert not has_timed_out(jobstep, jobplan, default_never)

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

        assert not has_timed_out(jobstep, jobplan, default_never)

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

        # Jobstep is has been allocated, not started running yet.
        assert not has_timed_out(jobstep, jobplan, default_never)

        jobstep.date_created = datetime.utcnow() - timedelta(minutes=181)

        db.session.add(jobstep)
        db.session.commit()

        # Too long pending allocation.
        assert has_timed_out(jobstep, jobplan, default_never)

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

        assert has_timed_out(jobstep, jobplan, default_never)

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

        assert has_timed_out(jobstep, jobplan, default_never)