-
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
06cac62
commit 0b9dee3
Showing
1 changed file
with
52 additions
and
39 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,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().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().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); |