mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-24 00:42:18 +00:00
✅ cover async shutdown failure path
This commit is contained in:
@@ -39,6 +39,7 @@ Detailed rules explaining key parameters and behaviors
|
||||
- `clear=true` immediately closes and abandons pending records.
|
||||
- In runtimes where shutdown waits for workers, the method then waits until `is_running()` becomes `false` before returning.
|
||||
- In the current backend split, native-worker runtimes enable both the post-`wait_idle()` clear fallback and the final wait-for-worker phase, while compatibility runtimes skip both extra steps.
|
||||
- That means a failure-short-circuited `wait_idle()` can still be followed by forced pending-to-dropped cleanup on native-worker runtimes, while compatibility runtimes close without that extra forced clear step.
|
||||
- Because `clear=false` delegates to `wait_idle()` first, shutdown can also wait indefinitely when pending records exist but no worker is making progress and no failure flag is raised.
|
||||
|
||||
### How to Use
|
||||
@@ -70,6 +71,8 @@ e.g.:
|
||||
|
||||
- If `wait_idle()` returns early because the worker failed, shutdown behavior after that point still depends on the active runtime's fallback and worker-wait rules.
|
||||
|
||||
- After a worker failure, native-worker shutdown may convert the remaining backlog into dropped records, while compatibility shutdown can leave the pending counter reflecting that leftover closed queue state.
|
||||
|
||||
- In compatibility-style runtimes without background-worker waiting, shutdown still closes the logger but may not perform the extra wait-for-worker phase described for native-worker runtimes.
|
||||
|
||||
- If pending work exists but no worker was started, `shutdown(clear=false)` may never reach its later close step because it is still waiting inside `wait_idle()`.
|
||||
|
||||
@@ -42,6 +42,7 @@ Detailed rules explaining key parameters and behaviors
|
||||
- If the active async runtime uses shutdown clearing after idle and backlog still remains, the wrapped logger falls back to `close(clear=true)`.
|
||||
- `clear=true` immediately closes and abandons pending records.
|
||||
- In runtimes where shutdown waits for workers, the method then waits until the worker is no longer running before returning.
|
||||
- After a worker-failure short-circuit, native-worker backends can still convert remaining backlog into dropped records, while compatibility backends skip that extra forced-clear step.
|
||||
- The narrower library facade does not change any of these runtime-dependent shutdown rules; it only keeps the broader inspection helpers out of the direct public surface.
|
||||
|
||||
### How to Use
|
||||
|
||||
@@ -406,6 +406,49 @@ async test "later started run resets async failure state before draining remaini
|
||||
inspect(logger.pending_count(), content="0")
|
||||
}
|
||||
|
||||
async test "shutdown after worker failure uses runtime-specific pending cleanup" {
|
||||
let writes : Ref[Int] = Ref(0)
|
||||
let logger = async_logger(
|
||||
@bitlogger.callback_sink(fn(_) {
|
||||
writes.val += 1
|
||||
}),
|
||||
config=AsyncLoggerConfig::new(
|
||||
max_pending=4,
|
||||
overflow=AsyncOverflowPolicy::Blocking,
|
||||
flush=AsyncFlushPolicy::Batch,
|
||||
),
|
||||
min_level=@bitlogger.Level::Info,
|
||||
target="async.failure.shutdown",
|
||||
flush=fn(_) -> Int raise {
|
||||
raise TestFlushError("flush exploded on shutdown path")
|
||||
},
|
||||
)
|
||||
|
||||
@async.with_task_group(group => {
|
||||
group.spawn_bg(allow_failure=true, () => logger.run())
|
||||
logger.info("one")
|
||||
logger.info("two")
|
||||
logger.wait_idle()
|
||||
inspect(logger.has_failed(), content="true")
|
||||
inspect(logger.pending_count(), content="1")
|
||||
logger.shutdown()
|
||||
})
|
||||
|
||||
inspect(logger.is_closed(), content="true")
|
||||
inspect(logger.has_failed(), content="true")
|
||||
inspect(logger.last_error().contains("TestFlushError"), content="true")
|
||||
inspect(logger.is_running(), content="false")
|
||||
inspect(writes.val, content="1")
|
||||
inspect(
|
||||
logger.pending_count(),
|
||||
content=if async_runtime_supports_background_worker() { "0" } else { "1" },
|
||||
)
|
||||
inspect(
|
||||
logger.dropped_count(),
|
||||
content=if async_runtime_supports_background_worker() { "1" } else { "0" },
|
||||
)
|
||||
}
|
||||
|
||||
async test "library async logger keeps a smaller async facade" {
|
||||
let written_targets : Ref[Array[String]] = Ref([])
|
||||
let written_messages : Ref[Array[String]] = Ref([])
|
||||
|
||||
Reference in New Issue
Block a user