Skip to content

Commit a449f13

Browse files
authored
Fix flaky unit test due to parallel test execution (#250)
1 parent 4414d5e commit a449f13

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

rclrs/src/node/graph.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ impl Node {
200200
}
201201

202202
/// Returns a list of all node names with enclaves.
203-
pub fn get_node_names_with_enclaves(
204-
&self,
205-
) -> Result<Vec<(String, String, String)>, RclrsError> {
203+
pub fn get_node_names_with_enclaves(&self) -> Result<Vec<(NodeNameInfo, String)>, RclrsError> {
206204
// SAFETY: Getting a zero-initialized value is always safe
207205
let (mut rcl_names, mut rcl_namespaces, mut rcl_enclaves) = unsafe {
208206
(
@@ -241,8 +239,10 @@ impl Node {
241239
.zip(enclaves_slice.iter())
242240
.map(|((name, namespace), enclave)| unsafe {
243241
(
244-
CStr::from_ptr(*name).to_string_lossy().into_owned(),
245-
CStr::from_ptr(*namespace).to_string_lossy().into_owned(),
242+
NodeNameInfo {
243+
name: CStr::from_ptr(*name).to_string_lossy().into_owned(),
244+
namespace: CStr::from_ptr(*namespace).to_string_lossy().into_owned(),
245+
},
246246
CStr::from_ptr(*enclave).to_string_lossy().into_owned(),
247247
)
248248
})
@@ -528,26 +528,30 @@ mod tests {
528528

529529
let names_and_namespaces = node.get_node_names().unwrap();
530530

531-
assert_eq!(
532-
names_and_namespaces,
533-
vec![NodeNameInfo {
534-
name: node_name.to_string(),
535-
namespace: "/".to_string()
536-
}]
537-
);
531+
// The tests are executed in parallel, so we might see some other nodes
532+
// in here. That's why we can't use assert_eq.
533+
assert!(names_and_namespaces.contains(&NodeNameInfo {
534+
name: node_name.to_string(),
535+
namespace: "/".to_string()
536+
}));
538537
}
539538

540539
#[test]
541540
fn test_node_names_with_enclaves() {
542541
let context = Context::new([]).unwrap();
543-
let node_name = "test_node_names";
542+
let node_name = "test_node_names_with_enclaves";
544543
let node = Node::new(&context, node_name).unwrap();
545544

546545
let names_and_namespaces = node.get_node_names_with_enclaves().unwrap();
547546

548-
assert_eq!(
549-
names_and_namespaces,
550-
vec![(node_name.to_string(), "/".to_string(), "/".to_string())]
551-
);
547+
// The tests are executed in parallel, so we might see some other nodes
548+
// in here. That's why we can't use assert_eq.
549+
assert!(names_and_namespaces.contains(&(
550+
NodeNameInfo {
551+
name: node_name.to_string(),
552+
namespace: "/".to_string()
553+
},
554+
"/".to_string()
555+
)));
552556
}
553557
}

0 commit comments

Comments
 (0)