Esempio n. 1
0
def test_log_corruption(mock_sleep, data_sequence, expected_exception,
                        mock_proxy):
    proxy_mock = mock_proxy()
    proxy_logs_mock = proxy_mock.scheduler.jobs.logs
    proxy_logs_mock.side_effect = data_sequence
    with expected_exception:
        retriable_follow_job(proxy_mock, "")
Esempio n. 2
0
def test_full_yaml_log(mock_proxy, frozen_time):
    import itertools
    import random
    from datetime import datetime

    import yaml

    def time_travel_from_log_chunk(data_chunk):
        if not data_chunk:
            return

        first_log_time = data_chunk[0]["dt"]
        frozen_time.move_to(first_log_time)
        yield

        last_log_time = data_chunk[-1]["dt"]
        frozen_time.move_to(last_log_time)
        return

    def time_travel_to_test_time():
        # Suppose that the first message timestamp of the entire LAVA job log is
        # the same of from the job submitter execution
        with open("/tmp/log.yaml", "r") as f:
            first_log = f.readline()
            first_log_time = yaml.safe_load(first_log)[0]["dt"]
            frozen_time.move_to(first_log_time)

    def load_lines() -> list:
        with open("/tmp/log.yaml", "r") as f:
            data = yaml.safe_load(f)
            chain = itertools.chain(data)
            try:
                while True:
                    data_chunk = [
                        next(chain) for _ in range(random.randint(0, 50))
                    ]
                    # Suppose that the first message timestamp is the same of
                    # log fetch RPC call
                    time_travel_from_log_chunk(data_chunk)
                    yield False, []
                    # Travel to the same datetime of the last fetched log line
                    # in the chunk
                    time_travel_from_log_chunk(data_chunk)
                    yield False, data_chunk
            except StopIteration:
                yield True, data_chunk
                return

    proxy = mock_proxy()

    def reset_logs(*args):
        proxy.scheduler.jobs.logs.side_effect = load_lines()

    proxy.scheduler.jobs.submit = reset_logs
    with pytest.raises(MesaCIRetryError):
        time_travel_to_test_time()
        retriable_follow_job(proxy, "")
Esempio n. 3
0
def test_retriable_follow_job(
    mock_sleep,
    test_log,
    expectation,
    job_result,
    proxy_args,
    mock_proxy,
):
    with expectation:
        proxy = mock_proxy(side_effect=test_log, **proxy_args)
        job: LAVAJob = retriable_follow_job(proxy, "")
        assert job_result == (job.status == "pass")
Esempio n. 4
0
def test_simulate_a_long_wait_to_start_a_job(
    frozen_time,
    wait_time,
    side_effect,
    has_finished,
    mock_proxy_waiting_time,
):
    start_time = datetime.now()
    result = retriable_follow_job(
        mock_proxy_waiting_time(frozen_time,
                                side_effect=side_effect,
                                wait_time=wait_time),
        "",
    )

    end_time = datetime.now()
    delta_time = end_time - start_time

    assert has_finished == result
    assert delta_time.total_seconds() >= wait_time
Esempio n. 5
0
def test_retriable_follow_job(mock_sleep, side_effect, expectation, job_result,
                              proxy_args, mock_proxy):
    with expectation:
        proxy = mock_proxy(side_effect=side_effect, **proxy_args)
        result = retriable_follow_job(proxy, "")
        assert job_result == result
def test_retriable_follow_job(mock_sleep, side_effect, expectation,
                              has_finished, mock_proxy):
    with expectation:
        result = retriable_follow_job(mock_proxy(side_effect=side_effect), "")
        assert has_finished == result