Esempio n. 1
0
def test_jobs_run_timeout(mock_url, replay_session):
    run_payload = {'id': 'myrun1'}
    job_payload = {
        'id': 'myjob',
        'history': {
            'successfulFinishedRuns': [run_payload],
            'failedFinishedRuns': []
        }
    }
    # lots of responses, but only a few will trigger before timeout
    mock_replay = list((
        MockResponse(run_payload, 201),
        MockResponse({}, 200),
        MockResponse({}, 200),
        MockResponse({}, 200),  # should timeout here
        MockResponse({}, 200),
        MockResponse({}, 200),
        MockResponse({}, 404),
        MockResponse(job_payload, 200),
    ))
    replay_session.queue(mock_replay)

    j = Jobs(default_url=mock_url)
    with pytest.raises(Exception):
        j.run('myapp1', timeout=2)

    assert len(replay_session.debug_cache) == 4
Esempio n. 2
0
def test_jobs_run_unknown_error(mock_url, replay_session):
    run_payload = {'id': 'myrun1'}
    exp_err_msg = 'Unexpected status code for job run myrun1: 500'
    mock_replay = list((
        MockResponse(run_payload, 201),
        MockResponse({}, 500),
    ))
    replay_session.queue(mock_replay)

    j = Jobs(default_url=mock_url)
    with pytest.raises(HTTPError) as http_error:
        j.run('myapp1')
    assert str(http_error.value) == exp_err_msg
    assert len(replay_session.debug_cache) == 2
Esempio n. 3
0
def test_jobs_run_failed_run(mock_url, replay_session):
    """Test the `run` method, which is a mixture of `start`
    and waiting (looping) on the run to complete.

    This test expects the Run to appear in the failed run list.
    """
    run_payload = {'id': 'myrun1'}
    job_payload = {
        'id': 'myjob',
        'history': {
            'successfulFinishedRuns': [],
            'failedFinishedRuns': [run_payload]
        }
    }
    # 2 200's to test timeout=1
    mock_replay = list((
        MockResponse(run_payload, 201),
        MockResponse({}, 404),
        MockResponse(job_payload, 200),
    ))
    replay_session.queue(mock_replay)

    j = Jobs(default_url=mock_url)
    success, run, job = j.run('myapp1')

    assert success is False
    assert run == run_payload
    assert job == job_payload
    assert len(replay_session.debug_cache) == 3
Esempio n. 4
0
def test_jobs_run_history_not_available(mock_url, replay_session):
    run_payload = {'id': 'myrun1'}
    job_payload = {
        'id': 'myjob',
        'history': {
            'successfulFinishedRuns': [],
            'failedFinishedRuns': []
        }
    }
    exp_err_msg = 'Waiting for job run myrun1 to be finished, but history for that job run is not available'

    # lots of responses, but only a few will trigger before timeout
    mock_replay = list((MockResponse(run_payload, 201), MockResponse({}, 404),
                        MockResponse(job_payload, 200), MockResponse({}, 404),
                        MockResponse(job_payload, 200), MockResponse({}, 404),
                        MockResponse(job_payload, 200), MockResponse({}, 404),
                        MockResponse(job_payload, 200)))
    replay_session.queue(mock_replay)

    j = Jobs(default_url=mock_url)
    with pytest.raises(Exception) as error:
        j.run('myapp1', timeout=2)

    assert str(error.value) == exp_err_msg