Example #1
0
    def test_should_raise_exception_for_multiple_scheduler_on_one_host(self):
        scheduler_jobs = []
        with create_session() as session:
            for _ in range(3):
                scheduler_job = SchedulerJob()
                scheduler_job.state = State.RUNNING
                scheduler_job.hostname = 'HOSTNAME'
                session.add(scheduler_job)
            session.commit()
            scheduler_job.heartbeat()

        with pytest.raises(SystemExit,
                           match=r"Found 3 alive jobs. Expected only one."):
            jobs_command.check(
                self.parser.parse_args([
                    'jobs',
                    'check',
                    '--job-type',
                    'SchedulerJob',
                    '--limit',
                    '100',
                ]))
        for scheduler_job in scheduler_jobs:
            if scheduler_job.processor_agent:
                scheduler_job.processor_agent.end()
Example #2
0
    def test_should_report_success_for_one_working_scheduler_with_hostname(
            self):
        with create_session() as session:
            job = SchedulerJob()
            job.state = State.RUNNING
            job.hostname = 'HOSTNAME'
            session.add(job)
            session.commit()
            job.heartbeat()

        with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
            jobs_command.check(
                self.parser.parse_args([
                    'jobs', 'check', '--job-type', 'SchedulerJob',
                    '--hostname', 'HOSTNAME'
                ]))
        self.assertIn("Found one alive job.", temp_stdout.getvalue())