Ejemplo n.º 1
0
def test_duplication_filter_configuration_errors(monkeypatch):
    monkeypatch.setenv('LOG_CACHE_EXPIRE', 0)
    with pytest.raises(ConfigurationWarning):
        LoggerDuplicationFilter()

    monkeypatch.setenv('LOG_CACHE_SIZE', 0)
    with pytest.raises(ConfigurationWarning):
        LoggerDuplicationFilter()
Ejemplo n.º 2
0
def test_duplication_filter_cache_size(monkeypatch):
    monkeypatch.setenv('LOG_CACHE_SIZE', 1)

    ft = LoggerDuplicationFilter()
    assert ft.filter(create_record(msg='repeated 1')) is True
    assert ft.filter(create_record(msg='repeated 2')) is True
    assert ft.filter(create_record(msg='repeated 1')) is True
    assert ft.filter(create_record(msg='repeated 2')) is True
    assert ft.filter(create_record(msg='repeated 2')) is False
Ejemplo n.º 3
0
def test_duplication_filter_respect_expire_time_and_cache_size(monkeypatch):
    monkeypatch.setenv('LOG_CACHE_SIZE', 2)
    monkeypatch.setenv('LOG_CACHE_EXPIRE', 1)

    ft = LoggerDuplicationFilter()
    assert ft.filter(create_record(msg='repeated 1')) is True
    assert ft.filter(create_record(msg='repeated 2')) is True
    assert ft.filter(create_record(msg='repeated 1')) is False
    assert ft.filter(create_record(msg='repeated 2')) is False
    time.sleep(1)
    assert ft.filter(create_record(msg='repeated 1')) is True
    assert ft.filter(create_record(msg='repeated 2')) is True
Ejemplo n.º 4
0
def test_cache_iteration(monkeypatch):
    monkeypatch.setenv('LOG_CACHE_SIZE', 2)

    ft = LoggerDuplicationFilter()
    ft.filter(create_record(msg='first item'))
    ft.filter(create_record(msg='second item'))

    # This call has no lock, so it raises the RuntimeError
    with pytest.raises(RuntimeError):
        for _ in ft._cache.items():
            ft.filter(create_record(msg='third item'))
Ejemplo n.º 5
0
def test_default_duplication_filter():
    ft = LoggerDuplicationFilter()
    assert ft.filter(create_record(msg='repeated')) is True
    assert ft.filter(create_record(msg='repeated')) is False
    assert ft.filter(create_record(msg='not repeated')) is True
Ejemplo n.º 6
0
def test_message_template_duplication_filter():
    ft = LoggerDuplicationFilter()
    assert ft.filter(create_record(msg='template %s', args=['teste'])) is True
    assert ft.filter(create_record(msg='template %s', args=['teste'])) is False
    assert ft.filter(create_record(msg='template %s', args=['teste2'])) is True