Skip to content
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 bad arguments tests for coverage #698

Merged
merged 16 commits into from
Jul 3, 2020
Prev Previous commit
Next Next commit
Add message_lost event test
Signed-off-by: Jorge Perez <[email protected]>
Blast545 committed Jun 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 06239c503275809f1ddeda4378e146d55e9f92a3
66 changes: 66 additions & 0 deletions rcl/test/rcl/test_events.cpp
Original file line number Diff line number Diff line change
@@ -696,6 +696,72 @@ TEST_P(TestEventFixture, test_pubsub_incompatible_qos)
tear_down_publisher_subscriber();
}

/*
* Basic test subscriber event message lost
*/
TEST_P(TestEventFixture, test_sub_message_lost_event)
{
const auto & input = GetParam();
const auto & subscription_qos_profile = input.subscription_qos_profile;
const auto & error_msg = input.error_msg;

rcl_ret_t ret = setup_subscriber(subscription_qos_profile);
ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;

// Check if supported
// Returns -11 for rmw_cyclonedds_cpp
subscription_event = rcl_get_zero_initialized_event();
ret = rcl_subscription_event_init(
&subscription_event,
&subscription,
RCL_SUBSCRIPTION_MESSAGE_LOST);
EXPECT_TRUE(ret == RCL_RET_OK || ret == RCL_RET_UNSUPPORTED);

if (ret == RCL_RET_UNSUPPORTED) {
// clean up and exit test early
ret = rcl_event_fini(&subscription_event);
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
ret = rcl_subscription_fini(&subscription, this->node_ptr);
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
return;
}

WaitConditionPredicate events_ready = [](
const bool & /*msg_persist_ready*/,
const bool & subscription_persist_ready,
const bool & /*publisher_persist_ready*/) {
return subscription_persist_ready;
};
bool msg_persist_ready, subscription_persist_ready, publisher_persist_ready;
rcl_ret_t wait_res = conditional_wait_for_msgs_and_events(
context_ptr, MAX_WAIT_PER_TESTCASE, events_ready,
&subscription, &subscription_event, nullptr,
&msg_persist_ready, &subscription_persist_ready, &publisher_persist_ready);
EXPECT_EQ(wait_res, RCL_RET_OK);

// test that the subscriber/datareader discovered a lost message event
EXPECT_TRUE(subscription_persist_ready);
if (subscription_persist_ready) {
rmw_message_lost_status_t message_lost_status;
rcl_ret_t ret = rcl_take_event(&subscription_event, &message_lost_status);
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
const auto & sub_total_count = message_lost_status.total_count;
const auto & sub_total_count_change = message_lost_status.total_count_change;
if (sub_total_count != 0 && sub_total_count_change != 0) {
EXPECT_EQ(sub_total_count, 1u) << error_msg;
EXPECT_EQ(sub_total_count_change, 1u) << error_msg;
} else {
ADD_FAILURE() << "Subscription incompatible message lost event timed out for: " << error_msg;
}
}

// clean up
ret = rcl_event_fini(&subscription_event);
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
ret = rcl_subscription_fini(&subscription, this->node_ptr);
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
}

/*
* Passing bad params to functions not covered with other tests
*/