aboutsummaryrefslogtreecommitdiffstats
path: root/components/background_hang_monitor
diff options
context:
space:
mode:
authorGregory Terzian <gterzian@users.noreply.github.com>2020-07-07 12:45:14 +0800
committerGregory Terzian <gterzian@users.noreply.github.com>2020-07-07 12:45:14 +0800
commit256167eff23a26a9a292c93b4136839e0332ac21 (patch)
tree762b23d847082fd38f13c540119534600642b467 /components/background_hang_monitor
parent39e3beb35c56ac58b3f3ec5307d5a1570bb56858 (diff)
downloadservo-256167eff23a26a9a292c93b4136839e0332ac21.tar.gz
servo-256167eff23a26a9a292c93b4136839e0332ac21.zip
improve reliability of hang monitor tests
Diffstat (limited to 'components/background_hang_monitor')
-rw-r--r--components/background_hang_monitor/background_hang_monitor.rs24
-rw-r--r--components/background_hang_monitor/tests/hang_monitor_tests.rs20
2 files changed, 26 insertions, 18 deletions
diff --git a/components/background_hang_monitor/background_hang_monitor.rs b/components/background_hang_monitor/background_hang_monitor.rs
index bc736402521..b97ec3bceec 100644
--- a/components/background_hang_monitor/background_hang_monitor.rs
+++ b/components/background_hang_monitor/background_hang_monitor.rs
@@ -33,17 +33,19 @@ impl HangMonitorRegister {
monitoring_enabled: bool,
) -> Box<dyn BackgroundHangMonitorRegister> {
let (sender, port) = unbounded();
- let _ = thread::Builder::new().spawn(move || {
- let mut monitor = BackgroundHangMonitorWorker::new(
- constellation_chan,
- control_port,
- port,
- monitoring_enabled,
- );
- while monitor.run() {
- // Monitoring until all senders have been dropped...
- }
- });
+ let _ = thread::Builder::new()
+ .spawn(move || {
+ let mut monitor = BackgroundHangMonitorWorker::new(
+ constellation_chan,
+ control_port,
+ port,
+ monitoring_enabled,
+ );
+ while monitor.run() {
+ // Monitoring until all senders have been dropped...
+ }
+ })
+ .expect("Couldn't start BHM worker.");
Box::new(HangMonitorRegister {
sender,
monitoring_enabled,
diff --git a/components/background_hang_monitor/tests/hang_monitor_tests.rs b/components/background_hang_monitor/tests/hang_monitor_tests.rs
index f379585b5e2..2dade559f84 100644
--- a/components/background_hang_monitor/tests/hang_monitor_tests.rs
+++ b/components/background_hang_monitor/tests/hang_monitor_tests.rs
@@ -197,12 +197,18 @@ fn test_hang_monitoring_exit_signal() {
);
let (exit_sender, exit_receiver) = ipc::channel().expect("Failed to create IPC channel!");
- // Send the exit message.
- let _ = control_sender.send(BackgroundHangMonitorControlMsg::Exit(exit_sender));
-
- // Assert we receive a confirmation back.
- assert!(exit_receiver.recv().is_ok());
- // Assert we get the exit signal.
- while !closing.load(Ordering::SeqCst) {}
+ // Send the exit message.
+ if control_sender
+ .send(BackgroundHangMonitorControlMsg::Exit(exit_sender))
+ .is_ok()
+ {
+ // Assert we receive a confirmation back.
+ assert!(exit_receiver.recv().is_ok());
+
+ // Assert we get the exit signal.
+ while !closing.load(Ordering::SeqCst) {
+ thread::sleep(Duration::from_millis(10));
+ }
+ }
}