Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
0
    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)
    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)