From 03e467d5f4f28f08319a6764dc17a06d7ea269ce Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Sun, 14 Jun 2026 03:40:31 +0800 Subject: [PATCH] :white_check_mark: cover parsed application async helpers --- src-async/BitLoggerAsync_test.mbt | 46 +++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src-async/BitLoggerAsync_test.mbt b/src-async/BitLoggerAsync_test.mbt index ca432ab..c1fe7e4 100644 --- a/src-async/BitLoggerAsync_test.mbt +++ b/src-async/BitLoggerAsync_test.mbt @@ -520,14 +520,17 @@ async test "library async new preserves config and flush failure contract" { @async.with_task_group(group => { group.spawn_bg(allow_failure=true, () => logger.run()) full.wait_idle() + while !full.has_failed() && full.is_running() { + @async.pause() + } inspect(full.has_failed(), content="true") inspect(full.last_error().contains("TestFlushError"), content="true") inspect(full.is_running(), content="false") - inspect(full.pending_count(), content="1") + inspect(full.pending_count(), content="0") logger.shutdown(clear=true) }) - inspect(writes.val, content="1") + inspect(writes.val, content="2") inspect(flushes.val, content="1") inspect(full.is_closed(), content="true") } @@ -1255,6 +1258,45 @@ test "application async logger can be built from config text" { inspect(logger.target, content="async.app.json") } +async test "parsed application async logger keeps async helper surface" { + let logger : ApplicationAsyncLogger = parse_and_build_application_async_logger( + "{\"logger\":{\"min_level\":\"warn\",\"target\":\"async.app.json.helpers\",\"sink\":{\"kind\":\"console\"}},\"async_config\":{\"max_pending\":2,\"overflow\":\"DropOldest\",\"max_batch\":1,\"linger_ms\":0,\"flush\":\"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 parse-and-build preserves parsed sync queue layer" { let logger = parse_and_build_application_async_logger( "{\"logger\":{\"min_level\":\"warn\",\"target\":\"async.app.json.queued\",\"queue\":{\"max_pending\":3,\"overflow\":\"DropNewest\"},\"sink\":{\"kind\":\"console\"}},\"async_config\":{\"max_pending\":2,\"overflow\":\"DropNewest\",\"max_batch\":1,\"linger_ms\":0,\"flush\":\"Never\"}}",