Allow multiple error message output from `match_v5_get[_timeline]` test helpers

pull/62/head
Mingwei Samuel 2023-11-15 11:00:19 -08:00
parent a9a0990d5c
commit dd77ffa6dd
1 changed files with 17 additions and 4 deletions

View File

@ -1,5 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use std::future::Future;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use riven::consts::{PlatformRoute, QueueType, RegionalRoute}; use riven::consts::{PlatformRoute, QueueType, RegionalRoute};
@ -157,8 +159,7 @@ pub async fn match_v5_get(
} }
Ok(()) Ok(())
}); });
futures::future::try_join_all(futures).await?; join_all_future_errs(futures).await
Ok(())
} }
pub async fn match_v5_get_timeline( pub async fn match_v5_get_timeline(
@ -191,6 +192,18 @@ pub async fn match_v5_get_timeline(
} }
Ok(()) Ok(())
}); });
futures::future::try_join_all(futures).await?; join_all_future_errs(futures).await
Ok(()) }
/// Joins all futures and keeps ALL error messages, separated by newlines.
async fn join_all_future_errs<T>(
result_tasks: impl Iterator<Item = impl Future<Output = Result<T, String>>>,
) -> Result<(), String> {
futures::future::join_all(result_tasks)
.await
.into_iter()
.filter_map(Result::err)
.reduce(|a, b| a + "\n" + &b)
.map(Err)
.unwrap_or(Ok(()))
} }