Skip to content

Commit

Permalink
test: Parametrize the method integration tests
Browse files Browse the repository at this point in the history
This drastically reduces boilerplate code when adding new tests.
  • Loading branch information
philipp-caspers committed Dec 16, 2024
1 parent 9377188 commit 530b2ec
Showing 1 changed file with 52 additions and 39 deletions.
91 changes: 52 additions & 39 deletions tests/test_bridge_methods.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
use std::{sync::{mpsc, Arc}, time::Duration};
use std::{
sync::{mpsc, Arc},
time::Duration,
};

use common::{wait_for_function_to_pass, ManagedRosBridge};

pub mod common;
pub mod helpers;

#[test]
fn e2e_ros_service_to_opc_ua_call() {
let (assertion_tx, assertion_rx) = mpsc::channel();
let (stop_opc_ua_server_tx, stop_opc_ua_server_rx) = mpsc::channel();
helpers::opc_ua_test_server::run_opc_ua_test_server(assertion_tx, stop_opc_ua_server_rx);

let mut _bridge_process = ManagedRosBridge::new(None).expect("Failed to start subprocess");

let service_caller = Arc::new(
helpers::ros_service_caller::ServiceCaller::new(
"/voraus_bridge_node/impedance_control/enable",
)
.unwrap(),
);

// TODO: Figure out why this takes almost 10 s [RR-836]
service_caller.start();
assert!(*service_caller.number_of_calls.lock().unwrap() == 0);
service_caller.call();

wait_for_function_to_pass(
|| *service_caller.number_of_calls.lock().unwrap() == 1,
5000,
)
.unwrap();

wait_for_function_to_pass(
|| {
let received = assertion_rx
.recv_timeout(Duration::from_millis(10))
.unwrap();
received.contains("impedance_control/enable")
},
5000,
)
.unwrap();

stop_opc_ua_server_tx.send(()).unwrap();
macro_rules! make_testcase_method {
($value:expr, $testname:ident) => {
#[test]
fn $testname() {
let (assertion_tx, assertion_rx) = mpsc::channel();
let (stop_opc_ua_server_tx, stop_opc_ua_server_rx) = mpsc::channel();
helpers::opc_ua_test_server::run_opc_ua_test_server(
assertion_tx,
stop_opc_ua_server_rx,
);

let mut _bridge_process = ManagedRosBridge::new(None).expect("Failed to start subprocess");

let service_caller = Arc::new(
helpers::ros_service_caller::ServiceCaller::new(&format!(
"/voraus_bridge_node/{}",
$value
))
.unwrap(),
);

// TODO: Figure out why this takes almost 10 s [RR-836]
service_caller.start();
assert!(*service_caller.number_of_calls.lock().unwrap() == 0);
service_caller.call();

wait_for_function_to_pass(
|| *service_caller.number_of_calls.lock().unwrap() == 1,
5000,
)
.unwrap();

wait_for_function_to_pass(
|| {
let received = assertion_rx
.recv_timeout(Duration::from_millis(10))
.unwrap();
received.contains($value)
},
5000,
)
.unwrap();

stop_opc_ua_server_tx.send(()).unwrap();
}
};
}

make_testcase_method!("impedance_control/enable", test_enable_impedance_control);

0 comments on commit 530b2ec

Please sign in to comment.