Skip to content

Commit 21d3b35

Browse files
committed
Improve the documentation for the domain ID situation of test_graph_empty
Signed-off-by: Michael X. Grey <[email protected]>
1 parent cf0d434 commit 21d3b35

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

rclrs/src/node/graph.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,28 @@ mod tests {
459459

460460
#[test]
461461
fn test_graph_empty() {
462+
// cargo test by default will run all test functions in parallel using
463+
// as many threads as the underlying system allows. However, the test
464+
// expectations of test_graph_empty will fail if its detects any other middleware
465+
// activity while it's running.
466+
//
467+
// If we ensure that the Context of test_graph_empty is given a different domain ID
468+
// from the rest of the tests, then we can ensure that it will not observe any other
469+
// middleware activity, and its expectations can pass (as long as the user is not
470+
// running any other ROS executables on their system).
471+
//
472+
// By default we will assign 99 to the domain ID of test_graph_empty's Context.
473+
// However, if the ROS_DOMAIN_ID environment variable was set to 99 by the user,
474+
// then the rest of the tests will be using that value. So here we are detecting
475+
// that situation and setting the domain ID of test_graph_empty's Context to 98
476+
// in that situation.
477+
//
478+
// 99 and 98 are just chosen as arbitrary valid domain ID values. There is
479+
// otherwise nothing special about either value.
462480
let domain_id: usize = std::env::var("ROS_DOMAIN_ID")
463481
.ok()
464482
.and_then(|value| value.parse().ok())
465-
.map(|value: usize| {
466-
if value == 99 {
467-
// The default domain ID for this application is 99, which
468-
// conflicts with our arbitrarily chosen default for the
469-
// empty graph test. Therefore we will set the empty graph
470-
// test domain ID to 98 instead.
471-
98
472-
} else {
473-
99
474-
}
475-
})
483+
.map(|value: usize| if value != 99 { 99 } else { 98 })
476484
.unwrap_or(99);
477485

478486
let context =

0 commit comments

Comments
 (0)