From 819612aec65f98de16dbb6a96d1a0f9e14ed3f9a Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 1 Jun 2020 20:04:29 -0300 Subject: [PATCH] Avoid multiple type topics in tests. (#1150) Signed-off-by: Michel Hidalgo --- .../test_subscription_topic_statistics.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/rclcpp/test/topic_statistics/test_subscription_topic_statistics.cpp b/rclcpp/test/topic_statistics/test_subscription_topic_statistics.cpp index 3a7e90c..74a79e6 100644 --- a/rclcpp/test/topic_statistics/test_subscription_topic_statistics.cpp +++ b/rclcpp/test/topic_statistics/test_subscription_topic_statistics.cpp @@ -46,6 +46,7 @@ namespace constexpr const char kTestPubNodeName[]{"test_pub_stats_node"}; constexpr const char kTestSubNodeName[]{"test_sub_stats_node"}; constexpr const char kTestSubStatsTopic[]{"/test_sub_stats_topic"}; +constexpr const char kTestSubStatsEmptyTopic[]{"/test_sub_stats_empty_topic"}; constexpr const char kTestTopicStatisticsTopic[]{"/test_topic_statistics_topic"}; constexpr const uint64_t kNoSamples{0}; constexpr const std::chrono::seconds kTestDuration{10}; @@ -210,21 +211,20 @@ protected: void SetUp() { rclcpp::init(0 /* argc */, nullptr /* argv */); - empty_subscriber = std::make_shared( - kTestSubNodeName, - kTestSubStatsTopic); } void TearDown() { rclcpp::shutdown(); - empty_subscriber.reset(); } - std::shared_ptr empty_subscriber; }; TEST_F(TestSubscriptionTopicStatisticsFixture, test_manual_construction) { + auto empty_subscriber = std::make_shared( + kTestSubNodeName, + kTestSubStatsEmptyTopic); + // Manually create publisher tied to the node auto topic_stats_publisher = empty_subscriber->create_publisher( @@ -251,7 +251,7 @@ TEST_F(TestSubscriptionTopicStatisticsFixture, test_receive_stats_for_message_no // Create an empty publisher auto empty_publisher = std::make_shared( kTestPubNodeName, - kTestSubStatsTopic); + kTestSubStatsEmptyTopic); // empty_subscriber has a topic statistics instance as part of its subscription // this will listen to and generate statistics for the empty message @@ -261,6 +261,10 @@ TEST_F(TestSubscriptionTopicStatisticsFixture, test_receive_stats_for_message_no "/statistics", 2); + auto empty_subscriber = std::make_shared( + kTestSubNodeName, + kTestSubStatsEmptyTopic); + rclcpp::executors::SingleThreadedExecutor ex; ex.add_node(empty_publisher); ex.add_node(statistics_listener);