Skip to content

Commit 9a3584a

Browse files
committed
[debug commit]
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent f360b2b commit 9a3584a

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

.github/workflows/ValidatePullRequest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
- docs-pr
6868
- build-guests
6969
strategy:
70-
fail-fast: true
70+
fail-fast: false
7171
matrix:
7272
hypervisor: [hyperv, 'hyperv-ws2025', mshv3, kvm]
7373
cpu: [amd, intel]

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ mod tests {
773773
use hyperlight_testing::tracing_subscriber::TracingSubscriber;
774774
use tracing::Level;
775775
use tracing_core::Subscriber;
776+
use tracing_core::callsite::rebuild_interest_cache;
776777
use uuid::Uuid;
777778

778779
/// Helper to extract a string value from nested JSON: obj["span"]["attributes"][key]
@@ -793,19 +794,25 @@ mod tests {
793794
let subscriber = TracingSubscriber::new(Level::TRACE);
794795

795796
tracing::subscriber::with_default(subscriber.clone(), || {
797+
// Rebuild the global callsite interest cache so that all callsites
798+
// (including those already registered by other test threads with the
799+
// no-op subscriber) are re-evaluated against our TracingSubscriber.
800+
// Without this, a race condition can cause #[instrument] spans in
801+
// production code to be permanently disabled via Interest::never().
802+
rebuild_interest_cache();
803+
796804
let correlation_id = Uuid::new_v4().to_string();
797805
let _span = tracing::error_span!("test_trace_logs", %correlation_id).entered();
798806

799-
// Verify we're in span 1 with correct name
800-
let (span_id, span_meta) = subscriber
807+
// Verify we're in a span with correct name
808+
let (test_span_id, span_meta) = subscriber
801809
.current_span()
802810
.into_inner()
803811
.expect("Should be inside a span");
804-
assert_eq!(span_id.into_u64(), 1, "Should be in span 1");
805812
assert_eq!(span_meta.name(), "test_trace_logs");
806813

807814
// Verify correlation_id was recorded
808-
let span_data = subscriber.get_span(1);
815+
let span_data = subscriber.get_span(test_span_id.into_u64());
809816
let recorded_id =
810817
get_span_attr(&span_data, "correlation_id").expect("correlation_id not found");
811818
assert_eq!(recorded_id, correlation_id);
@@ -816,16 +823,31 @@ mod tests {
816823
let result = UninitializedSandbox::new(GuestBinary::FilePath(bad_path), None);
817824
assert!(result.is_err(), "Sandbox creation should fail");
818825

819-
// Verify we're still in span 1 (our test span)
820-
let (span_id, _) = subscriber
826+
// Verify we're still in our test span
827+
let (current_id, _) = subscriber
821828
.current_span()
822829
.into_inner()
823830
.expect("Should still be inside a span");
824-
assert_eq!(span_id.into_u64(), 1, "Should still be in span 1");
831+
assert_eq!(
832+
current_id.into_u64(),
833+
test_span_id.into_u64(),
834+
"Should still be in the test span"
835+
);
825836

826-
// Verify span 2 was created by UninitializedSandbox::new
827-
let inner_span_meta = subscriber.get_span_metadata(2);
828-
assert_eq!(inner_span_meta.name(), "new");
837+
// Verify a span named "new" was created by UninitializedSandbox::new
838+
// (look up by name rather than hardcoded ID to avoid fragility)
839+
let all_spans = subscriber.get_all_spans();
840+
let new_span_entry = all_spans
841+
.iter()
842+
.find(|(&id, _)| {
843+
id != test_span_id.into_u64()
844+
&& subscriber.get_span_metadata(id).name() == "new"
845+
})
846+
.expect("Expected a span named 'new' from UninitializedSandbox::new");
847+
assert_eq!(
848+
subscriber.get_span_metadata(*new_span_entry.0).name(),
849+
"new"
850+
);
829851

830852
// Verify the error event was emitted
831853
let events = subscriber.get_events();

src/hyperlight_testing/src/tracing_subscriber.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use tracing::Subscriber;
2222
use tracing_core::event::Event;
2323
use tracing_core::metadata::Metadata;
2424
use tracing_core::span::{Attributes, Current, Id, Record};
25-
use tracing_core::{Level, LevelFilter};
25+
use tracing_core::{Interest, Level, LevelFilter};
2626
use tracing_serde::AsSerde;
2727

2828
#[derive(Debug, Clone)]
@@ -69,6 +69,11 @@ impl TracingSubscriber {
6969
EVENTS.with(|events| events.borrow().clone())
7070
}
7171

72+
/// Returns all recorded spans as a HashMap
73+
pub fn get_all_spans(&self) -> HashMap<u64, Value> {
74+
SPANS.with(|spans| spans.borrow().clone())
75+
}
76+
7277
pub fn test_trace_records<F: Fn(&HashMap<u64, Value>, &Vec<Value>)>(&self, f: F) {
7378
SPANS.with(|spans| {
7479
EVENTS.with(|events| {
@@ -88,6 +93,13 @@ impl TracingSubscriber {
8893
}
8994

9095
impl Subscriber for TracingSubscriber {
96+
fn register_callsite(&self, _metadata: &'static Metadata<'static>) -> Interest {
97+
// Return Interest::sometimes() to prevent the global interest cache from caching
98+
// our decision. This avoids race conditions when running tests in parallel,
99+
// since each call to enabled() will be re-evaluated per-thread.
100+
Interest::sometimes()
101+
}
102+
91103
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
92104
LEVEL_FILTER.with(|level_filter| metadata.level() <= &*level_filter.borrow())
93105
}

0 commit comments

Comments
 (0)