Skip to content

Commit

Permalink
add test_rtp_3p_bi_direction_sendrecv
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Feb 19, 2024
1 parent 113f54a commit 6b70ecb
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 110 deletions.
20 changes: 10 additions & 10 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn pretty_sdp(input: &str) -> String {
pub async fn setup_peer_connection(
config: RTCConfiguration,
endpoint_id: EndpointId,
) -> Result<(EndpointId, Arc<RTCPeerConnection>)> {
) -> Result<Arc<RTCPeerConnection>> {
let _ = env_logger::Builder::new()
.format(|buf, record| {
writeln!(
Expand Down Expand Up @@ -99,18 +99,20 @@ pub async fn setup_peer_connection(
Box::pin(async {})
}));

Ok((endpoint_id, peer_connection))
Ok(peer_connection)
}

pub async fn setup_peer_connections(
configs: Vec<RTCConfiguration>,
endpoint_ids: Vec<EndpointId>,
) -> Result<Vec<(EndpointId, Arc<RTCPeerConnection>)>> {
endpoint_ids: &[usize],
) -> Result<Vec<Arc<RTCPeerConnection>>> {
assert_eq!(configs.len(), endpoint_ids.len());

let mut peer_connections = Vec::with_capacity(configs.len());

for (config, endpoint_id) in configs.into_iter().zip(endpoint_ids) {
let (endpoint_id, peer_connection) = setup_peer_connection(config, endpoint_id).await?;
peer_connections.push((endpoint_id, peer_connection));
let peer_connection = setup_peer_connection(config, *endpoint_id as EndpointId).await?;
peer_connections.push(peer_connection);
}

Ok(peer_connections)
Expand All @@ -122,10 +124,8 @@ pub async fn teardown_peer_connection(pc: Arc<RTCPeerConnection>) -> Result<()>
Ok(())
}

pub async fn teardown_peer_connections(
pcs: Vec<(EndpointId, Arc<RTCPeerConnection>)>,
) -> Result<()> {
for (_, pc) in pcs {
pub async fn teardown_peer_connections(pcs: Vec<Arc<RTCPeerConnection>>) -> Result<()> {
for pc in pcs {
teardown_peer_connection(pc).await?;
}

Expand Down
32 changes: 22 additions & 10 deletions tests/data_channels_test.rs → tests/data_channel_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common::{HOST, SIGNAL_PORT};
use log::error;
use rand::random;
use sfu::SessionId;
use sfu::{EndpointId, SessionId};
use webrtc::ice_transport::ice_server::RTCIceServer;
use webrtc::peer_connection::configuration::RTCConfiguration;

Expand All @@ -12,6 +12,7 @@ mod common;
async fn test_data_channel() -> anyhow::Result<()> {
// Prepare the configuration
let session_id: SessionId = random::<u64>();
let endpoint_id = 0;
let config = RTCConfiguration {
ice_servers: vec![RTCIceServer {
urls: vec!["stun:stun.l.google.com:19302".to_owned()],
Expand All @@ -20,7 +21,7 @@ async fn test_data_channel() -> anyhow::Result<()> {
..Default::default()
};

let (endpoint_id, peer_connection) = match common::setup_peer_connection(config, 0).await {
let peer_connection = match common::setup_peer_connection(config, endpoint_id).await {
Ok(ok) => ok,
Err(err) => {
error!("error: {}", err);
Expand Down Expand Up @@ -49,6 +50,7 @@ async fn test_data_channel() -> anyhow::Result<()> {
#[tokio::test]
async fn test_data_channels() -> anyhow::Result<()> {
// Prepare the configuration
let endpoint_count: usize = 3;
let session_id: SessionId = random::<u64>();
let config = RTCConfiguration {
ice_servers: vec![RTCIceServer {
Expand All @@ -58,21 +60,31 @@ async fn test_data_channels() -> anyhow::Result<()> {
..Default::default()
};

let peer_connections = match common::setup_peer_connections(
vec![config.clone(), config.clone(), config],
vec![0, 1, 2],
)
.await
{
let mut configs = vec![];
let mut endpoint_ids = vec![];
for endpoint_id in 0..endpoint_count {
configs.push(config.clone());
endpoint_ids.push(endpoint_id);
}

let peer_connections = match common::setup_peer_connections(configs, &endpoint_ids).await {
Ok(ok) => ok,
Err(err) => {
error!("{}: error {}", session_id, err);
return Err(err.into());
}
};

for (endpoint_id, peer_connection) in peer_connections.iter() {
match common::connect(HOST, SIGNAL_PORT, session_id, *endpoint_id, peer_connection).await {
for (endpoint_id, peer_connection) in peer_connections.iter().enumerate() {
match common::connect(
HOST,
SIGNAL_PORT,
session_id,
endpoint_id as EndpointId,
peer_connection,
)
.await
{
Ok(ok) => ok,
Err(err) => {
error!("{}/{}: error {}", session_id, endpoint_id, err);
Expand Down
Loading

0 comments on commit 6b70ecb

Please sign in to comment.