From 11db21a500109fdd2416a55cf1ffd3013bf06738 Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Sun, 14 Jun 2026 03:21:09 +0800 Subject: [PATCH] :white_check_mark: cover application alias helper surface --- src-async/BitLoggerAsync_test.mbt | 50 +++++++++++++++++++++++++++++++ src/BitLogger_test.mbt | 29 ++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/src-async/BitLoggerAsync_test.mbt b/src-async/BitLoggerAsync_test.mbt index be28e7b..e0b1c19 100644 --- a/src-async/BitLoggerAsync_test.mbt +++ b/src-async/BitLoggerAsync_test.mbt @@ -991,6 +991,56 @@ test "application async logger aliases runtime async entry" { inspect(logger.target, content="async.app") } +async test "application async logger keeps async helper surface" { + let logger : ApplicationAsyncLogger = build_application_async_logger( + AsyncLoggerBuildConfig::new( + logger=@bitlogger.LoggerConfig::new( + min_level=@bitlogger.Level::Warn, + target="async.app.alias", + sink=@bitlogger.SinkConfig::new(kind=@bitlogger.SinkKind::Console), + ), + async_config=AsyncLoggerConfig::new( + max_pending=2, + overflow=AsyncOverflowPolicy::DropOldest, + flush=AsyncFlushPolicy::Shutdown, + ), + ), + ) + + let state = logger.state() + inspect(state.pending_count, content="0") + inspect(state.dropped_count, content="0") + inspect(state.is_closed, content="false") + inspect(state.is_running, content="false") + inspect(state.has_failed, content="false") + inspect(match state.flush_policy { + AsyncFlushPolicy::Never => "Never" + AsyncFlushPolicy::Batch => "Batch" + AsyncFlushPolicy::Shutdown => "Shutdown" + }, content="Shutdown") + + logger.info("skip") + logger.error("one") + logger.error("two") + logger.error("three") + inspect(logger.pending_count(), content="2") + inspect(logger.dropped_count(), content="1") + inspect(logger.is_closed(), content="false") + inspect(logger.is_running(), content="false") + + @async.with_task_group(group => { + group.spawn_bg(() => logger.run()) + logger.shutdown() + }) + + inspect(logger.is_closed(), content="true") + inspect(logger.is_running(), content="false") + inspect(logger.pending_count(), content="0") + inspect(logger.dropped_count(), content="1") + inspect(logger.has_failed(), content="false") + inspect(logger.last_error(), content="") +} + test "application async logger builder preserves sync queue-backed runtime sink" { let logger = build_application_async_logger( AsyncLoggerBuildConfig::new( diff --git a/src/BitLogger_test.mbt b/src/BitLogger_test.mbt index e0a35aa..c658580 100644 --- a/src/BitLogger_test.mbt +++ b/src/BitLogger_test.mbt @@ -1481,6 +1481,35 @@ test "application logger aliases configured runtime entry" { inspect(logger.target, content="app.runtime") } +test "application logger keeps configured runtime helper surface" { + let logger : ApplicationLogger = build_application_logger( + LoggerConfig::new( + min_level=Level::Warn, + target="app.alias.helpers", + sink=SinkConfig::new(kind=SinkKind::File, path="app-alias.log"), + queue=Some(QueueConfig::new(2, overflow=QueueOverflowPolicy::DropOldest)), + ), + ) + + logger.error("one") + logger.error("two") + logger.error("three") + inspect(logger.pending_count(), content="2") + inspect(logger.dropped_count(), content="1") + inspect(logger.file_policy().append, content="true") + inspect(logger.file_runtime_state() is None, content="false") + inspect(logger.flush(), content="2") + inspect(logger.pending_count(), content="0") + + if logger.file_available() { + inspect(logger.file_flush(), content="true") + inspect(logger.file_close(), content="true") + } else { + inspect(logger.file_flush(), content="false") + inspect(logger.file_close(), content="false") + } +} + test "application logger can be built from config text" { let logger = parse_and_build_application_logger( "{\"min_level\":\"warn\",\"target\":\"app.json\",\"sink\":{\"kind\":\"console\"}}",