@@ -85,9 +85,12 @@ pub(crate) fn maybe_time_and_emit_host_call<T, F: FnOnce() -> T>(
85
85
86
86
#[ cfg( test) ]
87
87
mod tests {
88
+ use std:: thread;
89
+ use std:: time:: Duration ;
90
+
88
91
use hyperlight_common:: flatbuffer_wrappers:: function_types:: { ParameterValue , ReturnType } ;
89
92
use hyperlight_testing:: simple_guest_as_string;
90
- use metrics:: Key ;
93
+ use metrics:: { with_local_recorder , Key } ;
91
94
use metrics_util:: CompositeKey ;
92
95
93
96
use super :: * ;
@@ -96,24 +99,24 @@ mod tests {
96
99
use crate :: { GuestBinary , UninitializedSandbox } ;
97
100
98
101
#[ test]
99
- #[ ignore = "This test needs to be run separately to avoid having other tests interfere with it" ]
100
102
fn test_metrics_are_emitted ( ) {
101
- // Set up the recorder and snapshotter
102
103
let recorder = metrics_util:: debugging:: DebuggingRecorder :: new ( ) ;
103
104
let snapshotter = recorder. snapshotter ( ) ;
104
-
105
- // we cannot use with_local_recorder, since that won't capture the metrics
106
- // emitted by the hypervisor-thread (which is all of them)
107
- recorder. install ( ) . unwrap ( ) ;
108
-
109
- let snapshot = {
105
+ let snapshot = with_local_recorder ( & recorder, || {
110
106
let uninit = UninitializedSandbox :: new (
111
107
GuestBinary :: FilePath ( simple_guest_as_string ( ) . unwrap ( ) ) ,
112
108
None ,
113
109
)
114
110
. unwrap ( ) ;
115
111
116
112
let mut multi = uninit. evolve ( Noop :: default ( ) ) . unwrap ( ) ;
113
+ let interrupt_handle = multi. interrupt_handle ( ) ;
114
+
115
+ // interrupt the guest function call to "Spin" after 1 second
116
+ let thread = thread:: spawn ( move || {
117
+ thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
118
+ assert ! ( interrupt_handle. kill( ) ) ;
119
+ } ) ;
117
120
118
121
multi
119
122
. call_guest_function_by_name (
@@ -126,9 +129,10 @@ mod tests {
126
129
multi
127
130
. call_guest_function_by_name ( "Spin" , ReturnType :: Int , None )
128
131
. unwrap_err ( ) ;
132
+ thread. join ( ) . unwrap ( ) ;
129
133
130
134
snapshotter. snapshot ( )
131
- } ;
135
+ } ) ;
132
136
133
137
// Convert snapshot into a hashmap for easier lookup
134
138
#[ expect( clippy:: mutable_key_type) ]
0 commit comments