Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions livekit/tests/common/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,39 @@ impl TestEnvironment {

/// Creates the specified number of connections to a shared room for testing.
pub async fn test_rooms(count: usize) -> Result<Vec<(Room, UnboundedReceiver<RoomEvent>)>> {
test_rooms_with_options((0..count).map(|_| RoomOptions::default())).await
}

/// Creates multiple connections to a shared room for testing, one for each configuration.
pub async fn test_rooms_with_options(
options: impl IntoIterator<Item = RoomOptions>,
) -> Result<Vec<(Room, UnboundedReceiver<RoomEvent>)>> {
let test_env = TestEnvironment::from_env_or_defaults();
let room_name = format!("test_room_{}", create_random_uuid());

let tokens = (0..count)
let tokens = options
.into_iter()
.map(|id| -> Result<String> {
.enumerate()
.map(|(id, options)| -> Result<(String, RoomOptions)> {
let grants =
VideoGrants { room_join: true, room: room_name.clone(), ..Default::default() };
Ok(AccessToken::with_api_key(&test_env.api_key, &test_env.api_secret)
let token = AccessToken::with_api_key(&test_env.api_key, &test_env.api_secret)
.with_ttl(Duration::from_secs(30 * 60)) // 30 minutes
.with_grants(grants)
.with_identity(&format!("p{}", id))
.to_jwt()
.context("Failed to generate JWT")?)
.context("Failed to generate JWT")?;
Ok((token, options))
})
.collect::<Result<Vec<_>>>()?;

let rooms = try_join_all(tokens.into_iter().map(|token| {
let rooms = try_join_all(tokens.into_iter().map(|(token, options)| {
let server_url = test_env.server_url.clone();
async move {
let options = RoomOptions::default();
Room::connect(&server_url, &token, options).await.context("Failed to connect to room")
}
}))
.await?;

Ok(rooms)
}
}
Loading