@@ -85,9 +85,12 @@ pub(crate) fn maybe_time_and_emit_host_call<T, F: FnOnce() -> T>(
8585
8686#[ cfg( test) ]
8787mod tests {
88+ use std:: thread;
89+ use std:: time:: Duration ;
90+
8891 use hyperlight_common:: flatbuffer_wrappers:: function_types:: { ParameterValue , ReturnType } ;
8992 use hyperlight_testing:: simple_guest_as_string;
90- use metrics:: Key ;
93+ use metrics:: { with_local_recorder , Key } ;
9194 use metrics_util:: CompositeKey ;
9295
9396 use super :: * ;
@@ -96,24 +99,24 @@ mod tests {
9699 use crate :: { GuestBinary , UninitializedSandbox } ;
97100
98101 #[ test]
99- #[ ignore = "This test needs to be run separately to avoid having other tests interfere with it" ]
100102 fn test_metrics_are_emitted ( ) {
101- // Set up the recorder and snapshotter
102103 let recorder = metrics_util:: debugging:: DebuggingRecorder :: new ( ) ;
103104 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, || {
110106 let uninit = UninitializedSandbox :: new (
111107 GuestBinary :: FilePath ( simple_guest_as_string ( ) . unwrap ( ) ) ,
112108 None ,
113109 )
114110 . unwrap ( ) ;
115111
116112 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+ } ) ;
117120
118121 multi
119122 . call_guest_function_by_name (
@@ -126,9 +129,10 @@ mod tests {
126129 multi
127130 . call_guest_function_by_name ( "Spin" , ReturnType :: Int , None )
128131 . unwrap_err ( ) ;
132+ thread. join ( ) . unwrap ( ) ;
129133
130134 snapshotter. snapshot ( )
131- } ;
135+ } ) ;
132136
133137 // Convert snapshot into a hashmap for easier lookup
134138 #[ expect( clippy:: mutable_key_type) ]
0 commit comments