diff --git a/crates/collab/src/db/tests/channel_tests.rs b/crates/collab/src/db/tests/channel_tests.rs index f82ae7d7737bf805fe884e4dea177a3added5008..75db9d619cdb735408b174ff7c36858556f17a1a 100644 --- a/crates/collab/src/db/tests/channel_tests.rs +++ b/crates/collab/src/db/tests/channel_tests.rs @@ -1,3 +1,4 @@ +use collections::{HashMap, HashSet}; use rpc::{proto, ConnectionId}; use crate::{ @@ -459,12 +460,12 @@ async fn test_channel_renames(db: &Arc) { } test_both_dbs!( - test_channels_moving, + test_db_channel_moving, test_channels_moving_postgres, test_channels_moving_sqlite ); -async fn test_channels_moving(db: &Arc) { +async fn test_db_channel_moving(db: &Arc) { let a_id = db .create_user( "user1@example.com", @@ -661,9 +662,9 @@ async fn test_channels_moving(db: &Arc) { (zed_id, None), (crdb_id, Some(zed_id)), (gpui2_id, Some(zed_id)), - (livestreaming_id, Some(gpui2_id)), (livestreaming_id, Some(zed_id)), (livestreaming_id, Some(crdb_id)), + (livestreaming_id, Some(gpui2_id)), (livestreaming_dag_id, Some(livestreaming_id)), (livestreaming_dag_sub_id, Some(livestreaming_id)), (livestreaming_dag_sub_id, Some(livestreaming_dag_id)), @@ -836,10 +837,25 @@ async fn test_channels_moving(db: &Arc) { #[track_caller] fn assert_dag(actual: Vec, expected: &[(ChannelId, Option)]) { + /// This is used to allow tests to be ordering independent + fn make_parents_map(association_table: impl IntoIterator)>) -> HashMap> { + let mut map: HashMap> = HashMap::default(); + + for (child, parent) in association_table { + let entry = map.entry(child).or_default(); + if let Some(parent) = parent { + entry.insert(parent); + } + } + + map + } let actual = actual .iter() - .map(|channel| (channel.id, channel.parent_id)) - .collect::>(); + .map(|channel| (channel.id, channel.parent_id)); + + let actual_map = make_parents_map(actual); + let expected_map = make_parents_map(expected.iter().copied()); - pretty_assertions::assert_eq!(actual, expected) + pretty_assertions::assert_eq!(actual_map, expected_map) }