From b6406013c5f49df81b6fb8ad8baabdd22586b837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Brzezi=C5=84ski?= Date: Wed, 21 Aug 2024 21:06:04 +0200 Subject: [PATCH] hlssink3: Fix racy test by separating events (signals) from bus messages Was regularly failing on the CI. Bus messages are handled async here, so they need to be tracked separately. Part-of: --- net/hlssink3/tests/hlssink3.rs | 40 +++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/net/hlssink3/tests/hlssink3.rs b/net/hlssink3/tests/hlssink3.rs index c84ff83b..f29a3011 100644 --- a/net/hlssink3/tests/hlssink3.rs +++ b/net/hlssink3/tests/hlssink3.rs @@ -130,6 +130,7 @@ fn test_hlssink3_element_with_video_content() -> Result<(), ()> { hlssink3.set_property_from_str("playlist-type", "unspecified"); let (hls_events_sender, hls_events_receiver) = mpsc::sync_channel(20); + let (hls_messages_sender, hls_messages_receiver) = mpsc::sync_channel(10); let playlist_content = Arc::new(Mutex::new(String::from(""))); hlssink3.connect("get-playlist-stream", false, { @@ -204,7 +205,7 @@ fn test_hlssink3_element_with_video_content() -> Result<(), ()> { if let Some(structure) = msg.structure() { if structure.has_name("hls-segment-added") { let location = structure.get::("location").unwrap(); - hls_events_sender + hls_messages_sender .try_send(HlsSinkEvent::SegmentAddedMessage(location)) .expect("Send segment added event"); } @@ -228,27 +229,38 @@ fn test_hlssink3_element_with_video_content() -> Result<(), ()> { vec![ GetFragmentStream("segment00000.ts".to_string()), GetPlaylistStream("playlist.m3u8".to_string()), - SegmentAddedMessage("segment00000.ts".to_string()), GetFragmentStream("segment00001.ts".to_string()), GetPlaylistStream("playlist.m3u8".to_string()), - SegmentAddedMessage("segment00001.ts".to_string()), GetFragmentStream("segment00002.ts".to_string()), GetPlaylistStream("playlist.m3u8".to_string()), DeleteFragment("segment00000.ts".to_string()), - SegmentAddedMessage("segment00002.ts".to_string()), GetFragmentStream("segment00003.ts".to_string()), GetPlaylistStream("playlist.m3u8".to_string()), DeleteFragment("segment00001.ts".into()), - SegmentAddedMessage("segment00003.ts".to_string()), GetFragmentStream("segment00004.ts".to_string()), GetPlaylistStream("playlist.m3u8".to_string()), DeleteFragment("segment00002.ts".to_string()), - SegmentAddedMessage("segment00004.ts".to_string()), GetPlaylistStream("playlist.m3u8".to_string()), ] }; assert_eq!(expected_ordering_of_events, actual_events); + let mut actual_messages = Vec::new(); + while let Ok(event) = hls_messages_receiver.recv_timeout(Duration::from_millis(1)) { + actual_messages.push(event); + } + let expected_messages = { + use self::HlsSinkEvent::*; + vec![ + SegmentAddedMessage("segment00000.ts".to_string()), + SegmentAddedMessage("segment00001.ts".to_string()), + SegmentAddedMessage("segment00002.ts".to_string()), + SegmentAddedMessage("segment00003.ts".to_string()), + SegmentAddedMessage("segment00004.ts".to_string()), + ] + }; + assert_eq!(expected_messages, actual_messages); + let contents = playlist_content.lock().unwrap(); assert_eq!( r###"#EXTM3U @@ -354,6 +366,7 @@ fn test_hlssink3_write_correct_playlist_content() -> Result<(), ()> { .expect("Must be able to instantiate hlssink3"); let (hls_events_sender, hls_events_receiver) = mpsc::sync_channel(20); + let (hls_messages_sender, hls_messages_receiver) = mpsc::sync_channel(10); let playlist_content = Arc::new(Mutex::new(String::from(""))); hlssink3.connect("get-playlist-stream", false, { @@ -428,7 +441,7 @@ fn test_hlssink3_write_correct_playlist_content() -> Result<(), ()> { if let Some(structure) = msg.structure() { if structure.has_name("hls-segment-added") { let location = structure.get::("location").unwrap(); - hls_events_sender + hls_messages_sender .try_send(HlsSinkEvent::SegmentAddedMessage(location)) .expect("Send segment added event"); } @@ -452,12 +465,23 @@ fn test_hlssink3_write_correct_playlist_content() -> Result<(), ()> { vec![ GetFragmentStream("/www/media/segments/my-own-filename-000.ts".to_string()), GetPlaylistStream("/www/media/main.m3u8".to_string()), - SegmentAddedMessage("/www/media/segments/my-own-filename-000.ts".to_string()), GetPlaylistStream("/www/media/main.m3u8".to_string()), ] }; assert_eq!(expected_ordering_of_events, actual_events); + let mut actual_messages = Vec::new(); + while let Ok(event) = hls_messages_receiver.recv_timeout(Duration::from_millis(1)) { + actual_messages.push(event); + } + let expected_messages = { + use self::HlsSinkEvent::*; + vec![SegmentAddedMessage( + "/www/media/segments/my-own-filename-000.ts".to_string(), + )] + }; + assert_eq!(expected_messages, actual_messages); + let contents = playlist_content.lock().unwrap(); assert_eq!( r###"#EXTM3U