Пример #1
0
def test_queue_peaks_no_lines_results(line_factory):
    """Test the QueuePeaks command.

    If there are no log lines processed, nothing should be returned.
    """
    cmd = commands.QueuePeaks()
    assert cmd.raw_results() == []
Пример #2
0
def test_queue_peaks_output(line_factory, capsys, output, expected):
    """Test the QueuePeaks command.

    Peaks information are returned sorted by date.
    """
    cmd = commands.QueuePeaks()
    for microseconds, queue in enumerate([0, 4, 0, 0, 19, 4, 0]):
        line = line_factory(queue_backend=queue,
                            accept_date=f'15/Jan/2017:05:23:05.{microseconds}')
        cmd(line)
    check_output(cmd, output, expected, capsys)
Пример #3
0
def test_queue_peaks_generated_keys(line_factory, date, expected_key):
    """Test the QueuePeaks command.

    Check how the keys for the requests dictionary are generated.
    """
    cmd = commands.QueuePeaks()
    cmd(line_factory(queue_backend=0, accept_date=date))
    keys = list(cmd.requests.keys())
    # account for a 1h difference, if UTC is used (as in travis)
    assert expected_key - 4000 <= keys[0] <= expected_key + 4000
    # check that microseconds are exact though
    assert expected_key - int(expected_key) == keys[0] - int(keys[0])
Пример #4
0
def test_queue_peaks_no_queues(line_factory):
    """Test the QueuePeaks command.

    If there are no log lines processed, nothing should be returned.
    """
    cmd = commands.QueuePeaks()
    now = datetime.now()
    for second in range(4):
        accept_date = now.replace(
            second=second).strftime('%d/%b/%Y:%H:%M:%S.%f')
        cmd(line_factory(queue_backend=0, accept_date=accept_date))
    assert len(cmd.requests) == 4
    assert cmd.raw_results() == []
Пример #5
0
def test_queue_peaks_multiple_sorted(line_factory):
    """Test the QueuePeaks command.

    Peaks information are returned sorted by date.
    """
    cmd = commands.QueuePeaks()
    for microseconds, queue in enumerate([0, 4, 0, 0, 19, 4, 0]):
        line = line_factory(queue_backend=queue,
                            accept_date=f'15/Jan/2017:05:23:05.{microseconds}')
        cmd(line)
    day = datetime(year=2017, month=1, day=15, hour=5, minute=23, second=5)
    results = cmd.raw_results()
    assert len(results) == 2
    assert results[0]['peak'] == 4
    assert results[0]['started'] == day.replace(microsecond=100000)
    assert results[1]['peak'] == 19
    assert results[1]['started'] == day.replace(microsecond=400000)
Пример #6
0
def test_queue_peaks_did_not_finish(line_factory):
    """Test the QueuePeaks command.

    Check that QueuePeaks handles the corner case of a peak that does not finish.
    """
    cmd = commands.QueuePeaks()
    for microseconds, queue in enumerate([4, 19, 12]):
        line = line_factory(queue_backend=queue,
                            accept_date=f'15/Jan/2017:05:23:05.{microseconds}')
        cmd(line)
    day = datetime(year=2017, month=1, day=15, hour=5, minute=23, second=5)
    results = cmd.raw_results()
    assert len(results) == 1
    peak_info = results[0]
    assert peak_info['peak'] == 19
    assert peak_info['span'] == 3
    assert peak_info['started'] == day
    assert peak_info['finished'] == day.replace(microsecond=200000)
Пример #7
0
def test_queue_peaks_details(line_factory):
    """Test the QueuePeaks command.

    Check the information returned for each peak.
    """
    cmd = commands.QueuePeaks()
    for microseconds, queue in enumerate([0, 4, 7, 8, 19, 4, 0]):
        line = line_factory(queue_backend=queue,
                            accept_date=f'15/Jan/2017:05:23:05.{microseconds}')
        cmd(line)
    day = datetime(year=2017, month=1, day=15, hour=5, minute=23, second=5)
    results = cmd.raw_results()
    assert len(results) == 1
    peak_info = results[0]
    assert peak_info['peak'] == 19
    assert peak_info['span'] == 5
    assert peak_info['started'] == day.replace(microsecond=100000)
    assert peak_info['finished'] == day.replace(microsecond=600000)