Пример #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()
Пример #2
0
 def test_should_ignore_not_running_jobs(self):
     with create_session() as session:
         for _ in range(3):
             job = SchedulerJob()
             job.state = State.SHUTDOWN
             session.add(job)
         session.commit()
     # No alive jobs found.
     with pytest.raises(SystemExit, match=r"No alive jobs found."):
         jobs_command.check(self.parser.parse_args(['jobs', 'check']))
Пример #3
0
    def test_should_report_success_for_one_working_scheduler(self):
        with create_session() as session:
            job = SchedulerJob()
            job.state = State.RUNNING
            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']))
        self.assertIn("Found one alive job.", temp_stdout.getvalue())
Пример #4
0
 def test_should_ignore_not_running_jobs(self):
     scheduler_jobs = []
     with create_session() as session:
         for _ in range(3):
             scheduler_job = SchedulerJob()
             scheduler_job.state = State.SHUTDOWN
             session.add(scheduler_job)
             scheduler_jobs.append(scheduler_job)
         session.commit()
     # No alive jobs found.
     with pytest.raises(SystemExit, match=r"No alive jobs found."):
         jobs_command.check(self.parser.parse_args(['jobs', 'check']))
     for scheduler_job in scheduler_jobs:
         if scheduler_job.processor_agent:
             scheduler_job.processor_agent.end()
Пример #5
0
    def test_should_report_success_for_ha_schedulers(self):
        with create_session() as session:
            for _ in range(3):
                job = SchedulerJob()
                job.state = State.RUNNING
                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', '--limit',
                    '100', '--allow-multiple'
                ]))
        self.assertIn("Found 3 alive jobs.", temp_stdout.getvalue())