示例#1
0
def test_RunnableQueue_job_timeout(mocker, exception):
    '''
    Add two jobs to the queue. The first times out, and then gets resubmitted for the next pass
    through the loop.
    '''
    queue = RunnableQueue(mocker.MagicMock(), mocker.MagicMock())
    queue.pause = mocker.MagicMock()
    job_cls = factory.dummy_job_factory(mocker,
                                        exception(),
                                        remaining_attempts=5)
    job1 = job_cls()
    job2 = job_cls()
    queue.JOB_PRIORITIES = {PauseQueueJob: 0, job_cls: 1}

    # RequestTimeoutError or ServerConnectionError will cause the queue to pause,
    # use our fake pause method instead
    def fake_pause() -> None:
        queue.add_job(PauseQueueJob())

    queue.pause.emit = fake_pause

    # Add two jobs that timeout during processing to the queue
    queue.add_job(job1)
    queue.add_job(job2)

    # attempt to process job1 knowing that it times out
    queue.process()
    assert queue.queue.qsize() == 2  # queue contains: job1, job2

    # now process after making it so job1 no longer times out
    job1.return_value = 'mock'
    queue.process()
    assert queue.queue.qsize() == 1  # queue contains: job2
    assert queue.queue.get(block=True) == (1, job2)
示例#2
0
def test_RunnableQueue_does_not_run_jobs_when_not_authed(mocker):
    '''
    Add a job to the queue, ensure we don't run it when not authenticated.
    '''
    queue = RunnableQueue(mocker.MagicMock(), mocker.MagicMock())
    queue.pause = mocker.MagicMock()
    job_cls = factory.dummy_job_factory(mocker, ApiInaccessibleError())
    queue.JOB_PRIORITIES = {PauseQueueJob: 0, job_cls: 1}

    # ApiInaccessibleError will cause the queue to pause, use our fake pause method instead
    def fake_pause() -> None:
        queue.add_job(PauseQueueJob())

    queue.pause.emit = fake_pause

    # Add a job that results in an ApiInaccessibleError to the queue
    job = job_cls()
    queue.add_job(job)

    # attempt to process job1 knowing that it times out
    queue.process()
    assert queue.queue.qsize() == 1  # queue contains: job1