From 77b92c00f9ba8a616be9c33ffdc27cb4b9bd5486 Mon Sep 17 00:00:00 2001 From: yukiendo-pfr Date: Fri, 16 Oct 2026 12:00:39 +0900 Subject: [PATCH 1/2] Wait for the graph to settle in DroppingTheStreamUnsubscribes --- rclcpp_async/test/test_topic_stream.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rclcpp_async/test/test_topic_stream.cpp b/rclcpp_async/test/test_topic_stream.cpp index cf19e4f..2e7a723 100644 --- a/rclcpp_async/test/test_topic_stream.cpp +++ b/rclcpp_async/test/test_topic_stream.cpp @@ -214,14 +214,24 @@ TEST_F(TopicStreamTest, DestroyingASuspendedWaiterDetachesIt) EXPECT_TRUE(next.handle.done()); } +// The graph is updated asynchronously, so a subscription change is not visible in the count at once. +size_t WaitForSubscriberCount(rclcpp::Node & node, const std::string & topic, size_t expected) +{ + auto deadline = std::chrono::steady_clock::now() + 5s; + while (node.count_subscribers(topic) != expected && std::chrono::steady_clock::now() < deadline) { + std::this_thread::sleep_for(10ms); + } + return node.count_subscribers(topic); +} + TEST_F(TopicStreamTest, DroppingTheStreamUnsubscribes) { std::weak_ptr> weak; { auto stream = ctx_->subscribe("dropped_stream_topic", 10); weak = stream; - EXPECT_EQ(node_->count_subscribers("dropped_stream_topic"), 1u); + EXPECT_EQ(WaitForSubscriberCount(*node_, "dropped_stream_topic", 1u), 1u); } EXPECT_TRUE(weak.expired()); - EXPECT_EQ(node_->count_subscribers("dropped_stream_topic"), 0u); + EXPECT_EQ(WaitForSubscriberCount(*node_, "dropped_stream_topic", 0u), 0u); } From f46c15db8fa98b5032fcb1d15924a590c4d5c5a2 Mon Sep 17 00:00:00 2001 From: yukiendo-pfr Date: Fri, 16 Oct 2026 12:06:59 +0900 Subject: [PATCH 2/2] Keep the comment within the line length limit --- rclcpp_async/test/test_topic_stream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rclcpp_async/test/test_topic_stream.cpp b/rclcpp_async/test/test_topic_stream.cpp index 2e7a723..8953779 100644 --- a/rclcpp_async/test/test_topic_stream.cpp +++ b/rclcpp_async/test/test_topic_stream.cpp @@ -214,7 +214,7 @@ TEST_F(TopicStreamTest, DestroyingASuspendedWaiterDetachesIt) EXPECT_TRUE(next.handle.done()); } -// The graph is updated asynchronously, so a subscription change is not visible in the count at once. +// The graph is updated asynchronously, so the count does not reflect a change at once. size_t WaitForSubscriberCount(rclcpp::Node & node, const std::string & topic, size_t expected) { auto deadline = std::chrono::steady_clock::now() + 5s;