v0.1.2-pre.002-fix

This commit is contained in:
2026-08-14 18:10:38 +02:00
parent 7b4444fb07
commit 697527675a
7 changed files with 153 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-logging-lib/src/settings.rs
// version: 1
// version: 2
/// Runtime filter level used by KSP logging settings.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
@@ -216,13 +216,13 @@ impl LoggingSettings {
);
}
}
if let std::option::Option::Some(file) = self.file.as_ref() {
if file.file_name_prefix().is_empty() {
return std::result::Result::Err(
ksp_core_lib::Error::new(crate::ERROR_CODE_INVALID_SETTINGS, "file name prefix must not be empty")
.with_context("field", "file.file_name_prefix"),
);
}
if let std::option::Option::Some(file) = self.file.as_ref()
&& file.file_name_prefix().is_empty()
{
return std::result::Result::Err(
ksp_core_lib::Error::new(crate::ERROR_CODE_INVALID_SETTINGS, "file name prefix must not be empty")
.with_context("field", "file.file_name_prefix"),
);
}
return std::result::Result::Ok(());
}

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-logging-lib/src/span.rs
// version: 1
// version: 2
/// KSP-owned handle to a tracing span.
#[derive(Clone, Debug)]
@@ -28,8 +28,7 @@ impl Span {
/// Instruments an asynchronous future with a KSP span.
///
/// The span is entered whenever the future is polled and exited whenever it yields, so no enter guard is held across an `.await` point.
#[must_use]
/// The span is entered whenever the future is polled or dropped and exited when that operation returns, so no enter guard is held across an `.await` point.
pub fn instrument<F>(span: crate::Span, future: F) -> impl std::future::Future<Output = F::Output>
where
F: std::future::Future,

View File

@@ -1,5 +1,7 @@
// file: crates/ksp-logging-lib/tests/callsite.rs
// version: 1
// version: 2
//! Integration tests for KSP logging callsite and async span instrumentation behavior.
const TEST_TARGET: &str = "ksp-logging-lib";
@@ -137,7 +139,7 @@ fn span_macro_preserves_consumer_callsite() {
}
#[test]
fn async_instrumentation_enters_and_exits_span_during_poll() {
fn async_instrumentation_enters_and_exits_span_during_poll_and_drop() {
let captured = std::sync::Arc::new(std::sync::Mutex::new(std::vec::Vec::new()));
let enters = std::sync::Arc::new(std::sync::atomic::AtomicU64::new(0));
let exits = std::sync::Arc::new(std::sync::atomic::AtomicU64::new(0));
@@ -150,8 +152,12 @@ fn async_instrumentation_enters_and_exits_span_during_poll() {
let mut context = std::task::Context::from_waker(waker);
let poll = std::future::Future::poll(future.as_mut(), &mut context);
assert_eq!(poll, std::task::Poll::Ready(42_u32));
assert_eq!(enters.load(std::sync::atomic::Ordering::Relaxed), 1);
assert_eq!(exits.load(std::sync::atomic::Ordering::Relaxed), 1);
std::mem::drop(future);
assert_eq!(enters.load(std::sync::atomic::Ordering::Relaxed), 2);
assert_eq!(exits.load(std::sync::atomic::Ordering::Relaxed), 2);
return;
});
assert_eq!(enters.load(std::sync::atomic::Ordering::Relaxed), 1);
assert_eq!(exits.load(std::sync::atomic::Ordering::Relaxed), 1);
assert_eq!(enters.load(std::sync::atomic::Ordering::Relaxed), exits.load(std::sync::atomic::Ordering::Relaxed));
}

View File

@@ -1,5 +1,7 @@
// file: crates/ksp-logging-lib/tests/public_api.rs
// version: 1
// version: 2
//! Integration tests for the public crate-root surface of `ksp-logging-lib`.
const TEST_TARGET: &str = "ksp-logging-lib";