Skip to content

Commit 115d998

Browse files
committed
Simplify tests
Long ago it used `kill`, which didn't guarantee immediate delivery. Later, we transitioned to `raise`, which does guarantee. So we don't have to jump through loops to wait for the data to arrive.
1 parent 4d5fd6a commit 115d998

File tree

1 file changed

+4
-26
lines changed
  • signal-hook-registry/src

1 file changed

+4
-26
lines changed

signal-hook-registry/src/lib.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,6 @@ pub fn unregister_signal(signal: c_int) -> bool {
743743
mod tests {
744744
use std::sync::atomic::{AtomicUsize, Ordering};
745745
use std::sync::Arc;
746-
use std::thread;
747-
use std::time::Duration;
748746

749747
#[cfg(not(windows))]
750748
use libc::{pid_t, SIGUSR1, SIGUSR2};
@@ -782,18 +780,8 @@ mod tests {
782780
register(SIGUSR2, action).unwrap();
783781
libc::raise(SIGUSR2);
784782
}
785-
for _ in 0..10 {
786-
thread::sleep(Duration::from_millis(100));
787-
let current = status.load(Ordering::Relaxed);
788-
match current {
789-
// Not yet
790-
0 => continue,
791-
// Good, we are done with the correct result
792-
_ if current == 1 => return,
793-
_ => panic!("Wrong result value {}", current),
794-
}
795-
}
796-
panic!("Timed out waiting for the signal");
783+
let current = status.load(Ordering::Relaxed);
784+
assert_eq!(current, 1, "Wrong status value");
797785
}
798786

799787
#[test]
@@ -828,18 +816,8 @@ mod tests {
828816
register_sigaction(SIGUSR2, action).unwrap();
829817
libc::raise(SIGUSR2);
830818
}
831-
for _ in 0..10 {
832-
thread::sleep(Duration::from_millis(100));
833-
let current = status.load(Ordering::Relaxed);
834-
match current {
835-
// Not yet (PID == 0 doesn't happen)
836-
0 => continue,
837-
// Good, we are done with the correct result
838-
_ if current == pid as usize => return,
839-
_ => panic!("Wrong status value {}", current),
840-
}
841-
}
842-
panic!("Timed out waiting for the signal");
819+
let current = status.load(Ordering::Relaxed);
820+
assert_eq!(current, pid as usize, "Wrong status value");
843821
}
844822

845823
/// Check that registration works as expected and that unregister tells if it did or not.

0 commit comments

Comments
 (0)