Exemplo n.º 1
0
def test_forgetful_buffering_handler_emit_collects_log_records():
    handler = module.Forgetful_buffering_handler(byte_capacity=100, log_level=1)
    handler.emit(flexmock(getMessage=lambda: 'foo'))
    handler.emit(flexmock(getMessage=lambda: 'bar'))

    assert handler.buffer == ['foo\n', 'bar\n']
    assert not handler.forgot
Exemplo n.º 2
0
def test_format_buffered_logs_for_payload_flattens_log_buffer():
    handler = module.Forgetful_buffering_handler(byte_capacity=100, log_level=1)
    handler.buffer = ['foo\n', 'bar\n']
    flexmock(module.logging).should_receive('getLogger').and_return(flexmock(handlers=[handler]))

    payload = module.format_buffered_logs_for_payload()

    assert payload == 'foo\nbar\n'
Exemplo n.º 3
0
def test_format_buffered_logs_for_payload_inserts_truncation_indicator_when_logs_forgotten():
    handler = module.Forgetful_buffering_handler(byte_capacity=100, log_level=1)
    handler.buffer = ['foo\n', 'bar\n']
    handler.forgot = True
    flexmock(module.logging).should_receive('getLogger').and_return(flexmock(handlers=[handler]))

    payload = module.format_buffered_logs_for_payload()

    assert payload == '...\nfoo\nbar\n'
Exemplo n.º 4
0
def test_destroy_monitor_removes_healthchecks_handler():
    logger = logging.getLogger()
    original_handlers = list(logger.handlers)
    logger.addHandler(
        module.Forgetful_buffering_handler(byte_capacity=100, log_level=1))

    module.destroy_monitor(flexmock(), flexmock(), flexmock(), flexmock())

    assert logger.handlers == original_handlers
Exemplo n.º 5
0
def test_forgetful_buffering_handler_emit_forgets_log_records_when_capacity_reached():
    handler = module.Forgetful_buffering_handler(byte_capacity=len('foo\nbar\n'), log_level=1)
    handler.emit(flexmock(getMessage=lambda: 'foo'))
    assert handler.buffer == ['foo\n']
    handler.emit(flexmock(getMessage=lambda: 'bar'))
    assert handler.buffer == ['foo\n', 'bar\n']
    handler.emit(flexmock(getMessage=lambda: 'baz'))
    assert handler.buffer == ['bar\n', 'baz\n']
    handler.emit(flexmock(getMessage=lambda: 'quux'))
    assert handler.buffer == ['quux\n']
    assert handler.forgot