Skip to content

Commit

Permalink
Create test to prevent behavior regression
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
mjcarroll committed Apr 11, 2023
1 parent 7a72499 commit 67a1607
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions rclcpp/test/rclcpp/executors/test_executors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,49 @@ TEST(TestExecutors, testSpinUntilFutureCompleteNodePtr) {

rclcpp::shutdown();
}

TYPED_TEST(TestExecutors, testIntraprocessRetrigger) {
using ExecutorType = TypeParam;
ExecutorType executor;

const std::string kTopic = "~/test_service_intraprocess";
const size_t kNumMessages = 100;

auto ipc_node = std::make_shared<rclcpp::Node>("node");
rclcpp::PublisherOptions po;
po.use_intra_process_comm = rclcpp::IntraProcessSetting::Enable;
auto pub = ipc_node->create_publisher<test_msgs::msg::Empty>(kTopic, 1, po);

std::atomic_int counter = 0;
auto count_subs = [&counter](std::shared_ptr<const test_msgs::msg::Empty>) {
counter.fetch_add(1);
};

rclcpp::SubscriptionOptions so;
so.use_intra_process_comm = rclcpp::IntraProcessSetting::Enable;
auto sub = ipc_node->create_subscription<test_msgs::msg::Empty>(kTopic, kNumMessages, count_subs, so);

executor.add_node(ipc_node);

EXPECT_EQ(0, counter.load());
pub->publish(test_msgs::msg::Empty());

const std::chrono::milliseconds sleep_per_loop(10);
while (1u != counter.load()) {
rclcpp::sleep_for(sleep_per_loop);
executor.spin_some();
}
EXPECT_EQ(1u, counter.load());

// reset counter
counter.store(0);

for (size_t ii = 0; ii < kNumMessages; ++ii)
{
pub->publish(test_msgs::msg::Empty());
}
auto timer = ipc_node->create_wall_timer(std::chrono::milliseconds(250), [&executor](){executor.cancel();});
executor.spin();

EXPECT_EQ(kNumMessages, counter.load());
}

0 comments on commit 67a1607

Please sign in to comment.