unregister components while exiting

This commit is contained in:
csmoe 2018-12-15 21:55:58 +08:00
parent c9229f3f99
commit 5600a1dca1
5 changed files with 44 additions and 0 deletions

View file

@ -105,3 +105,30 @@ fn test_hang_monitoring() {
// Still no new alerts because the hang monitor has shut-down already.
assert!(background_hang_monitor_receiver.try_recv().is_err());
}
#[test]
fn test_hang_monitoring_unregister() {
let (background_hang_monitor_ipc_sender, background_hang_monitor_receiver) =
ipc::channel().expect("ipc channel failure");
let background_hang_monitor_register =
HangMonitorRegister::init(background_hang_monitor_ipc_sender.clone());
let background_hang_monitor = background_hang_monitor_register.register_component(
MonitoredComponentId(TEST_PIPELINE_ID, MonitoredComponentType::Script),
Duration::from_millis(10),
Duration::from_millis(1000),
);
// Start an activity.
let hang_annotation = HangAnnotation::Script(ScriptHangAnnotation::AttachLayout);
background_hang_monitor.notify_activity(hang_annotation);
// Unregister the component.
background_hang_monitor.unregister();
// Sleep until the "transient" timeout has been reached.
thread::sleep(Duration::from_millis(10));
// No new alert yet
assert!(background_hang_monitor_receiver.try_recv().is_err());
}