-
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: Parametrize the method integration tests
This drastically reduces boilerplate code when adding new tests.
- Loading branch information
1 parent
fbc0958
commit 178b070
Showing
1 changed file
with
53 additions
and
32 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 |
---|---|---|
@@ -1,39 +1,60 @@ | ||
use std::sync::{mpsc, Arc}; | ||
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().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(); | ||
bridge_process.terminate(); | ||
assert!(bridge_process | ||
.get_std_err() | ||
.unwrap() | ||
.contains("ROS service called")); | ||
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().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(); | ||
|
||
bridge_process.terminate(); | ||
stop_opc_ua_server_tx.send(()).unwrap(); | ||
} | ||
}; | ||
} | ||
|
||
make_testcase_method!("impedance_control/enable", test_enable_impedance_control); |