Skip to content

Commit

Permalink
tests: Add udp sender/receiver
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric authored and joaoantoniocardoso committed Jan 14, 2025
1 parent 8ad8940 commit 3effbcc
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/udp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use anyhow::*;
use clap::Parser;
use mavlink_server::{cli, drivers, hub, logger, stats, web};
use tracing::*;

#[tokio::test(flavor = "multi_thread", worker_threads = 10)]
async fn test_udpserver_receive_only() -> Result<()> {
cli::init_with(cli::Args::parse_from(vec![
"", // For some unknown reason, the first argument is ignored
"udpclient:0.0.0.0:3333",
"udpserver://0.0.0.0:3333?direction=receiver",
"--mavlink-heartbeat-frequency",
"10",
]));

for driver in cli::endpoints() {
hub::add_driver(driver).await?;
}

stats::set_period(tokio::time::Duration::from_millis(100)).await?;
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
for (uuid, driver) in stats::drivers_stats().await? {
if *driver.name == "UdpServer" {
assert!(driver.stats.output.is_none());
assert!(driver.stats.input.is_some());
}

if *driver.name == "UdpClient" {
assert!(driver.stats.output.is_some());
assert!(driver.stats.input.is_none());
}
}

for (id, driver_info) in hub::drivers().await? {
debug!("Removing driver id {id:?} ({driver_info:?})");
hub::remove_driver(id).await?;
}

Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 10)]
#[ignore]
async fn test_udpserver_send_only() -> Result<()> {
cli::init_with(cli::Args::parse_from(vec![
"", // For some unknown reason, the first argument is ignored
"udpclient:0.0.0.0:3333",
"udpserver://0.0.0.0:3333?direction=sender",
"--mavlink-heartbeat-frequency",
"10",
]));

for driver in cli::endpoints() {
hub::add_driver(driver).await?;
}

stats::set_period(tokio::time::Duration::from_millis(100)).await?;
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
for (uuid, driver) in stats::drivers_stats().await? {
if *driver.name == "UdpServer" {
assert!(driver.stats.output.is_some());
assert!(driver.stats.input.is_none());
}

if *driver.name == "UdpClient" {
assert!(driver.stats.output.is_some());
assert!(driver.stats.input.is_some());
}
}

for (id, driver_info) in hub::drivers().await? {
debug!("Removing driver id {id:?} ({driver_info:?})");
hub::remove_driver(id).await?;
}

Ok(())
}

0 comments on commit 3effbcc

Please sign in to comment.