Skip to content

Commit 60e308a

Browse files
fix(logger): add test for flush without buffer
Co-authored-by: leandrodamascena <[email protected]>
1 parent aaca9de commit 60e308a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/functional/logger/required_dependencies/test_powertools_logger_buffer.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,30 @@ def handler(event, context):
391391
assert len(log) == 0
392392

393393

394+
def test_flush_buffer_log_output_without_buffer_config(stdout, service_name, lambda_context, monkeypatch):
395+
# Set initial trace ID for first Lambda invocation
396+
monkeypatch.setenv(constants.XRAY_TRACE_ID_ENV, "1-67c39786-5908a82a246fb67f3089263f")
397+
398+
# GIVEN A logger without buffer configuration
399+
logger = Logger(level="DEBUG", service=service_name, stream=stdout)
400+
401+
@logger.inject_lambda_context(flush_buffer_on_uncaught_error=True)
402+
def handler(event, context):
403+
# Log messages are not buffered and should be output immediately
404+
logger.debug("debug message - 1")
405+
logger.debug("debug message - 2")
406+
raise ValueError("Test error")
407+
408+
# WHEN Invoking the handler and expecting a ValueError
409+
# AND flush_buffer_on_uncaught_error is True but there is no logger buffer configuration
410+
with pytest.raises(ValueError):
411+
handler({}, lambda_context)
412+
413+
# THEN Verify that log messages are flushed without any exception
414+
log = capture_multiple_logging_statements_output(stdout)
415+
assert len(log) == 2, "Expected two log messages"
416+
417+
394418
def test_buffer_configuration_and_buffer_propagation_across_logger_instances(stdout, service_name, monkeypatch):
395419
monkeypatch.setenv(constants.XRAY_TRACE_ID_ENV, "1-67c39786-5908a82a246fb67f3089263f")
396420

0 commit comments

Comments
 (0)