-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Implement central integration test
which tests all components working together properly. Co-authored-by: Jan-Niklas Burfeind <[email protected]>
- Loading branch information
1 parent
a8133b2
commit a54a932
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::{ | ||
process::Command, | ||
sync::{atomic::Ordering, Arc}, | ||
time::Duration, | ||
}; | ||
|
||
pub mod helpers; | ||
|
||
#[tokio::test] | ||
async fn e2e_opc_ua_var_to_ros_topic() { | ||
// Start the OPC UA server in the background | ||
helpers::opc_ua_publisher_single_linear::run_rapid_clock().await; | ||
|
||
println!("Starting ros bridge"); | ||
let mut bridge = Command::new("ros2") | ||
.args(["run"]) | ||
.args(["voraus_ros_bridge"]) | ||
.args(["voraus_ros_bridge"]) | ||
.spawn() | ||
.expect("Failed to run command"); | ||
|
||
// Spawn ROS Subscriber against a sample topic | ||
println!("Creating Subscription"); | ||
let subscription = Arc::new( | ||
helpers::ros_subscriber::Subscriber::new("joint_states_subscriber", "joint_states") | ||
.unwrap(), | ||
); | ||
let timeout = Some(Duration::new(5, 0)); | ||
rclrs::spin_once(subscription.node.clone(), timeout).expect("Could not spin"); | ||
|
||
let mut number_of_messages_received = subscription.num_messages.load(Ordering::SeqCst); | ||
let first_value = *subscription | ||
.data | ||
.lock() | ||
.unwrap() | ||
.as_ref() | ||
.unwrap() | ||
.position | ||
.first() | ||
.unwrap(); | ||
assert_eq!(number_of_messages_received, 1); | ||
|
||
rclrs::spin_once(subscription.node.clone(), timeout).expect("Could not spin"); | ||
|
||
number_of_messages_received = subscription.num_messages.load(Ordering::SeqCst); | ||
assert_eq!(number_of_messages_received, 2); | ||
let second_value = *subscription | ||
.data | ||
.lock() | ||
.unwrap() | ||
.as_ref() | ||
.unwrap() | ||
.position | ||
.first() | ||
.unwrap(); | ||
|
||
println!("{}, {}", first_value, second_value); | ||
assert!( | ||
second_value > first_value, | ||
"{} is not greater than {}", | ||
second_value, | ||
first_value | ||
); | ||
bridge | ||
.kill() | ||
.expect("voraus-ros-bridge process could not be killed."); | ||
println!("done"); | ||
} |