Skip to content

Commit

Permalink
Make tests in test_graph.cpp more reliable (#854)
Browse files Browse the repository at this point in the history
* Make WaitForAllNodesAlive in test_graph.cpp more reliable, also fix leaks

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>

* WaitForAllNodesAlive -> wait_for_all_nodes_alive

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored Nov 4, 2020
1 parent 900a059 commit 8a495c0
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions rcl/test/rcl/test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ class NodeGraphMultiNodeFixture : public CLASSNAME(TestGraphFixture, RMW_IMPLEME
std::placeholders::_2,
"/",
std::placeholders::_3);
WaitForAllNodesAlive();
wait_for_all_nodes_alive();
}

void TearDown() override
Expand All @@ -944,27 +944,25 @@ class NodeGraphMultiNodeFixture : public CLASSNAME(TestGraphFixture, RMW_IMPLEME
delete this->remote_context_ptr;
}

void WaitForAllNodesAlive()
void wait_for_all_nodes_alive()
{
rcl_ret_t ret;
rcutils_string_array_t node_names = rcutils_get_zero_initialized_string_array();
rcutils_string_array_t node_namespaces = rcutils_get_zero_initialized_string_array();
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
ret = rcutils_string_array_fini(&node_names);
ASSERT_EQ(RCUTILS_RET_OK, ret);
ret = rcutils_string_array_fini(&node_namespaces);
ASSERT_EQ(RCUTILS_RET_OK, ret);
});
// wait for all 3 nodes to be discovered: remote_node, old_node, node
size_t attempts = 0;
size_t max_attempts = 4;
while (node_names.size < 3) {
size_t attempts = 0u;
size_t max_attempts = 10u;
size_t last_size = 0u;
do {
std::this_thread::sleep_for(std::chrono::seconds(1));
ret = rcl_get_node_names(this->remote_node_ptr, allocator, &node_names, &node_namespaces);
rcutils_string_array_t node_names = rcutils_get_zero_initialized_string_array();
rcutils_string_array_t node_namespaces = rcutils_get_zero_initialized_string_array();
ASSERT_EQ(
RCL_RET_OK,
rcl_get_node_names(this->remote_node_ptr, allocator, &node_names, &node_namespaces));
attempts++;
last_size = node_names.size;
ASSERT_EQ(RCUTILS_RET_OK, rcutils_string_array_fini(&node_names));
ASSERT_EQ(RCUTILS_RET_OK, rcutils_string_array_fini(&node_namespaces));
ASSERT_LE(attempts, max_attempts) << "Unable to attain all required nodes";
}
} while (last_size < 3u);
}

/**
Expand Down

0 comments on commit 8a495c0

Please sign in to comment.