feat: harden community production foundation through story 1.5

This commit is contained in:
2026-08-14 00:21:59 +03:00
parent c30461cc92
commit f6fc2e5c9b
161 changed files with 16758 additions and 2515 deletions
@@ -0,0 +1,60 @@
use std::sync::Arc;
use crank_observability::{current_request_correlation, with_request_correlation};
#[tokio::test]
async fn concurrent_request_correlation_is_task_local() {
let barrier = Arc::new(tokio::sync::Barrier::new(2));
let first = observe(
"request-first",
"0af7651916cd43dd8448eb211c80319c",
Arc::clone(&barrier),
);
let second = observe(
"request-second",
"1af7651916cd43dd8448eb211c80319c",
barrier,
);
let (first, second) = tokio::join!(first, second);
assert_eq!(
first,
(
Some("request-first".to_owned()),
Some("0af7651916cd43dd8448eb211c80319c".to_owned()),
)
);
assert_eq!(
second,
(
Some("request-second".to_owned()),
Some("1af7651916cd43dd8448eb211c80319c".to_owned()),
)
);
assert_eq!(current_request_correlation(), (None, None));
}
#[tokio::test]
async fn invalid_correlation_strings_never_enter_task_local_state() {
let observed = with_request_correlation(
"bad request id".to_owned(),
"CANARY-NOT-A-TRACE-ID".to_owned(),
async { current_request_correlation() },
)
.await;
assert_eq!(observed, (None, None));
}
async fn observe(
request_id: &str,
trace_id: &str,
barrier: Arc<tokio::sync::Barrier>,
) -> (Option<String>, Option<String>) {
with_request_correlation(request_id.to_owned(), trace_id.to_owned(), async move {
barrier.wait().await;
tokio::task::yield_now().await;
current_request_correlation()
})
.await
}