-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fault injection macro unit tests #27
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,6 +23,7 @@ | |||||
|
||||||
#include "osrf_testing_tools_cpp/scope_exit.hpp" | ||||||
|
||||||
#include "rcutils/testing/fault_injection.h" | ||||||
#include "rmw/qos_profiles.h" | ||||||
#include "rmw/topic_endpoint_info.h" | ||||||
#include "rmw/topic_endpoint_info_array.h" | ||||||
|
@@ -1550,3 +1551,64 @@ TEST(test_graph_cache, bad_arguments) | |||||
rcutils_reset_error(); | ||||||
} | ||||||
} | ||||||
|
||||||
TEST(test_graph_cache, get_writers_info_by_topic_maybe_fail) | ||||||
{ | ||||||
RCUTILS_FAULT_INJECTION_TEST( | ||||||
{ | ||||||
GraphCache graph_cache; | ||||||
add_participants(graph_cache, {"participant1"}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this init section be left out of the fault_injection test macro? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so. I created a test fixture class and split this test into three separate TEST_Fs |
||||||
add_entities( | ||||||
graph_cache, | ||||||
{ | ||||||
// topic1 | ||||||
{"reader1", "participant1", "topic1", "Str", true}, | ||||||
{"writer1", "participant1", "topic1", "Str", false}, | ||||||
}); | ||||||
add_nodes( | ||||||
graph_cache, { | ||||||
{"participant1", "ns1", "node1"}, | ||||||
{"participant1", "ns1", "node2"}, | ||||||
{"participant1", "ns2", "node1"}}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brawner perhaps not an issue, but should the test fixture be setup outside the fault injection loop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah, created a test fixture class. |
||||||
|
||||||
rmw_topic_endpoint_info_array_t info = rmw_get_zero_initialized_topic_endpoint_info_array(); | ||||||
|
||||||
rcutils_allocator_t allocator = rcutils_get_default_allocator(); | ||||||
rmw_ret_t ret = graph_cache.get_writers_info_by_topic( | ||||||
"topic1", | ||||||
identity_demangle, | ||||||
&allocator, | ||||||
&info); | ||||||
if (RMW_RET_OK == ret) { | ||||||
ret = rmw_topic_endpoint_info_array_fini(&info, &allocator); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brawner should this be:
Suggested change
instead? Also, what if fault injection occurs here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it will fail during a fault injection test because there will be at least one hook in there. I added a check on the return of fini just in case it needs be done a second time. |
||||||
} else { | ||||||
rcutils_reset_error(); | ||||||
} | ||||||
|
||||||
rcutils_string_array_t names = rcutils_get_zero_initialized_string_array(); | ||||||
rcutils_string_array_t namespaces = rcutils_get_zero_initialized_string_array(); | ||||||
rcutils_string_array_t enclaves = rcutils_get_zero_initialized_string_array(); | ||||||
ret = graph_cache.get_node_names(&names, &namespaces, &enclaves, &allocator); | ||||||
if (RMW_RET_OK == ret) { | ||||||
ret = rcutils_string_array_fini(&names); | ||||||
ret = rcutils_string_array_fini(&namespaces); | ||||||
ret = rcutils_string_array_fini(&enclaves); | ||||||
} else { | ||||||
rcutils_reset_error(); | ||||||
} | ||||||
|
||||||
DemangleFunctionT demangle_topic = identity_demangle; | ||||||
DemangleFunctionT demangle_type = identity_demangle; | ||||||
rmw_names_and_types_t names_and_types = rmw_get_zero_initialized_names_and_types(); | ||||||
ret = graph_cache.get_names_and_types( | ||||||
demangle_topic, | ||||||
demangle_type, | ||||||
&allocator, | ||||||
&names_and_types); | ||||||
if (RMW_RET_OK == ret) { | ||||||
ret = rmw_names_and_types_fini(&names_and_types); | ||||||
} else { | ||||||
rcutils_reset_error(); | ||||||
} | ||||||
}); | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brawner would it make sense to split this test case into three separate ones (i.e. one for each method being fault injected).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done! I think I originally intended for that given the test name.