From b7da30d741e5047316d1e314cbc2184b856f958b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 29 Oct 2022 01:10:51 +0200 Subject: [PATCH] added unittest for all subscription --- fsrc-core/src/event_man.rs | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/fsrc-core/src/event_man.rs b/fsrc-core/src/event_man.rs index d050a70..6135613 100644 --- a/fsrc-core/src/event_man.rs +++ b/fsrc-core/src/event_man.rs @@ -18,7 +18,12 @@ //! manager. //! 4. Each event receiver and/or subscriber gets a receiver component. The sender component is //! used with the [SendEventProvider] trait and the subscription API provided by the -//! [EventManager] to subscribe for individual events or whole group of events. +//! [EventManager] to subscribe for individual events, whole group of events or all events +//! +//! Some components like a PUS Event Service or PUS Event Action Service might require all +//! events to package them as telemetry or start actions where applicable. +//! Other components might only be interested in certain events. For example, a thermal system +//! handler might only be interested in temperature events generated by a thermal sensor component. use crate::events::{GenericEvent, LargestEventRaw, LargestGroupIdRaw}; use alloc::boxed::Box; use alloc::vec; @@ -402,4 +407,36 @@ mod tests { assert!(res.is_ok()); check_handled_event(res.unwrap(), event_1, 1); } + + #[test] + fn test_all_events_listener() { + let (event_sender, manager_queue) = channel(); + let event_man_receiver = MpscEventReceiver { + mpsc_receiver: manager_queue, + }; + let mut event_man: EventManager, EventU32> = + EventManager::new(Box::new(event_man_receiver), 128); + let event_0 = EventU32::new(Severity::INFO, 0, 5).unwrap(); + let event_1 = EventU32::new(Severity::HIGH, 1, 0).unwrap(); + let (event_0_tx_0, all_events_rx) = channel(); + let all_events_listener = MpscEventSenderQueue { + id: 0, + mpsc_sender: event_0_tx_0, + }; + event_man.subscribe_all(all_events_listener); + event_sender + .send((event_0, None)) + .expect("Triggering event 0 failed"); + event_sender + .send((event_1, None)) + .expect("Triggering event 1 failed"); + let res = event_man.try_event_handling(); + assert!(res.is_ok()); + check_handled_event(res.unwrap(), event_0, 1); + let res = event_man.try_event_handling(); + assert!(res.is_ok()); + check_handled_event(res.unwrap(), event_1, 1); + check_next_event(event_0, &all_events_rx); + check_next_event(event_1, &all_events_rx); + } }