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

Test SubscriptionOptions::ignore_local_publications #192

Merged
merged 5 commits into from
Jul 2, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions test_rmw_implementation/test/test_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,22 @@ TEST_F(CLASSNAME(TestSubscriptionUse, RMW_IMPLEMENTATION), ignore_local_publicat
rmw_publisher_options_t pub_options = rmw_get_default_publisher_options();
rmw_publisher_t * pub = rmw_create_publisher(node, ts, topic_name, &qos_profile, &pub_options);
ASSERT_NE(nullptr, pub) << rmw_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
EXPECT_EQ(RMW_RET_OK, rmw_destroy_publisher(node, pub)) << rmw_get_error_string().str;
});

jamoralp marked this conversation as resolved.
Show resolved Hide resolved
// Create subscription with ignore_local_publications = true
rmw_subscription_options_t sub_options_ignorelocal = rmw_get_default_subscription_options();
sub_options_ignorelocal.ignore_local_publications = true;
rmw_subscription_t * sub_ignorelocal =
rmw_create_subscription(node, ts, topic_name, &qos_profile, &sub_options_ignorelocal);
ASSERT_NE(nullptr, sub_ignorelocal) << rmw_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
EXPECT_EQ(
RMW_RET_OK, rmw_destroy_subscription(node, sub_ignorelocal)) << rmw_get_error_string().str;
});

jamoralp marked this conversation as resolved.
Show resolved Hide resolved
size_t subscription_count = 0u;
SLEEP_AND_RETRY_UNTIL(rmw_intraprocess_discovery_delay, rmw_intraprocess_discovery_delay * 10) {
Expand All @@ -554,47 +563,63 @@ TEST_F(CLASSNAME(TestSubscriptionUse, RMW_IMPLEMENTATION), ignore_local_publicat
original_message.bool_value = true;
jamoralp marked this conversation as resolved.
Show resolved Hide resolved
original_message.char_value = 'k';
original_message.float32_value = 3.14159f;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
test_msgs__msg__BasicTypes__fini(&original_message);
});

rmw_publisher_allocation_t * null_allocation_p{nullptr};
rmw_subscription_allocation_t * null_allocation_s{nullptr};

// ignore_local_publications = true
ret = rmw_publish(pub, &original_message, null_allocation_p);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;

rmw_subscriptions_t subscriptions;
void * subscriptions_storage[2];
subscriptions_storage[0] = sub_ignorelocal->data;
subscriptions_storage[1] = sub->data;
subscriptions.subscribers = subscriptions_storage;
subscriptions.subscriber_count = 2;

rmw_wait_set_t * wait_set = rmw_create_wait_set(&context, 2);
ASSERT_NE(nullptr, wait_set) << rmw_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
ret = rmw_publish(pub, &original_message, null_allocation_p);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
EXPECT_EQ(
RMW_RET_OK, rmw_destroy_wait_set(wait_set)) << rmw_get_error_string().str;
});
rmw_time_t timeout = {1, 0}; // 1000ms
ret = rmw_wait(&subscriptions, nullptr, nullptr, nullptr, nullptr, wait_set, &timeout);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
jamoralp marked this conversation as resolved.
Show resolved Hide resolved

// ignore_local_publications = true
{
test_msgs__msg__BasicTypes output_message{};
ASSERT_TRUE(test_msgs__msg__BasicTypes__init(&output_message));
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
test_msgs__msg__BasicTypes__fini(&output_message);
});

ret = rmw_take(sub_ignorelocal, &output_message, &taken, null_allocation_s);
jamoralp marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
EXPECT_FALSE(taken);
test_msgs__msg__BasicTypes__fini(&output_message);
}

// ignore_local_publications = false
{
ret = rmw_publish(pub, &original_message, null_allocation_p);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;

test_msgs__msg__BasicTypes output_message{};
ASSERT_TRUE(test_msgs__msg__BasicTypes__init(&output_message));
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
test_msgs__msg__BasicTypes__fini(&output_message);
});

std::chrono::milliseconds take_delay(100);
SLEEP_AND_RETRY_UNTIL(take_delay, take_delay * 10) {
ret = rmw_take(sub, &output_message, &taken, null_allocation_s);
if (RMW_RET_OK == ret && taken) {
break;
}
}
ret = rmw_take(sub, &output_message, &taken, null_allocation_s);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
EXPECT_TRUE(taken);
EXPECT_EQ(original_message, output_message);
test_msgs__msg__BasicTypes__fini(&output_message);
}

test_msgs__msg__BasicTypes__fini(&original_message);
ret = rmw_destroy_publisher(node, pub);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
ret = rmw_destroy_subscription(node, sub_ignorelocal);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
}

TEST_F(CLASSNAME(TestSubscriptionUse, RMW_IMPLEMENTATION), take_sequence) {
Expand Down