File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -684,6 +684,12 @@ pub extern fn alarm_signal_handler(raw_signal: libc::c_int) {
684684#[ test]
685685#[ cfg( not( target_os = "redox" ) ) ]
686686fn test_alarm ( ) {
687+ use std:: {
688+ time:: { Duration , Instant , } ,
689+ thread
690+ } ;
691+
692+ // Maybe other tests that fork interfere with this one?
687693 let _m = crate :: SIGNAL_MTX . lock ( ) . expect ( "Mutex got poisoned by another test" ) ;
688694
689695 let handler = SigHandler :: Handler ( alarm_signal_handler) ;
@@ -701,8 +707,16 @@ fn test_alarm() {
701707
702708 // We should be woken up after 1 second by the alarm, so we'll sleep for 2
703709 // seconds to be sure.
704- sleep ( 2 ) ;
705- assert_eq ! ( unsafe { ALARM_CALLED } , true , "expected our alarm signal handler to be called" ) ;
710+ let starttime = Instant :: now ( ) ;
711+ loop {
712+ thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
713+ if unsafe { ALARM_CALLED } {
714+ break ;
715+ }
716+ if starttime. elapsed ( ) > Duration :: from_secs ( 3 ) {
717+ panic ! ( "Timeout waiting for SIGALRM" ) ;
718+ }
719+ }
706720
707721 // Reset the signal.
708722 unsafe {
You can’t perform that action at this time.
0 commit comments