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 18, 2024
1 parent c77a839 commit 3de8ad5
Showing 1 changed file with 43 additions and 35 deletions.
78 changes: 43 additions & 35 deletions tests/test_bridge_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,47 @@ use helpers::opc_ua_test_server::OPCUATestServer;
pub mod common;
pub mod helpers;

#[test]
fn e2e_ros_service_to_opc_ua_call() {
let (assertion_tx, assertion_rx) = mpsc::channel();
let _server = OPCUATestServer::new(assertion_tx);

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();
macro_rules! make_testcase_method {
($value:expr, $testname:ident) => {
#[test]
fn $testname() {
let (assertion_tx, assertion_rx) = mpsc::channel();
let _server = OPCUATestServer::new(assertion_tx);

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();
}
};
}

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

0 comments on commit 3de8ad5

Please sign in to comment.