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) {
684
684
#[ test]
685
685
#[ cfg( not( target_os = "redox" ) ) ]
686
686
fn test_alarm ( ) {
687
+ use std:: {
688
+ time:: { Duration , Instant , } ,
689
+ thread
690
+ } ;
691
+
692
+ // Maybe other tests that fork interfere with this one?
687
693
let _m = crate :: SIGNAL_MTX . lock ( ) . expect ( "Mutex got poisoned by another test" ) ;
688
694
689
695
let handler = SigHandler :: Handler ( alarm_signal_handler) ;
@@ -701,8 +707,16 @@ fn test_alarm() {
701
707
702
708
// We should be woken up after 1 second by the alarm, so we'll sleep for 2
703
709
// 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
+ }
706
720
707
721
// Reset the signal.
708
722
unsafe {
You can’t perform that action at this time.
0 commit comments