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

Update data callback tests to account for all published samples. #1900

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions rclcpp/test/rclcpp/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,15 @@ TEST_F(TestClient, on_new_response_callback) {
auto client_node = std::make_shared<rclcpp::Node>("client_node", "ns");
auto server_node = std::make_shared<rclcpp::Node>("server_node", "ns");

auto client = client_node->create_client<test_msgs::srv::Empty>("test_service");
rmw_qos_profile_t client_qos = rmw_qos_profile_services_default;
client_qos.depth = 3;
auto client = client_node->create_client<test_msgs::srv::Empty>("test_service", client_qos);
std::atomic<size_t> server_requests_count {0};
auto server_callback = [&server_requests_count](
const test_msgs::srv::Empty::Request::SharedPtr,
test_msgs::srv::Empty::Response::SharedPtr) {server_requests_count++;};
auto server = server_node->create_service<test_msgs::srv::Empty>("test_service", server_callback);
auto server = server_node->create_service<test_msgs::srv::Empty>(
"test_service", server_callback, client_qos);
auto request = std::make_shared<test_msgs::srv::Empty::Request>();

std::atomic<size_t> c1 {0};
Expand Down Expand Up @@ -422,7 +425,7 @@ TEST_F(TestClient, on_new_response_callback) {
start = std::chrono::steady_clock::now();
do {
std::this_thread::sleep_for(100ms);
} while (c3 == 0 && std::chrono::steady_clock::now() - start < 10s);
} while (c3 < 3 && std::chrono::steady_clock::now() - start < 10s);

EXPECT_EQ(c1.load(), 1u);
EXPECT_EQ(c2.load(), 1u);
Expand Down
10 changes: 7 additions & 3 deletions rclcpp/test/rclcpp/test_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,17 @@ TEST_F(TestService, on_new_request_callback) {
auto server_callback =
[](const test_msgs::srv::Empty::Request::SharedPtr,
test_msgs::srv::Empty::Response::SharedPtr) {FAIL();};
auto server = node->create_service<test_msgs::srv::Empty>("~/test_service", server_callback);
rmw_qos_profile_t service_qos = rmw_qos_profile_services_default;
service_qos.depth = 3;
auto server = node->create_service<test_msgs::srv::Empty>(
"~/test_service", server_callback, service_qos);

std::atomic<size_t> c1 {0};
auto increase_c1_cb = [&c1](size_t count_msgs) {c1 += count_msgs;};
server->set_on_new_request_callback(increase_c1_cb);

auto client = node->create_client<test_msgs::srv::Empty>("~/test_service");
auto client = node->create_client<test_msgs::srv::Empty>(
"~/test_service", service_qos);
{
auto request = std::make_shared<test_msgs::srv::Empty::Request>();
client->async_send_request(request);
Expand Down Expand Up @@ -297,7 +301,7 @@ TEST_F(TestService, on_new_request_callback) {
start = std::chrono::steady_clock::now();
do {
std::this_thread::sleep_for(100ms);
} while (c3 == 0 && std::chrono::steady_clock::now() - start < 10s);
} while (c3 < 3 && std::chrono::steady_clock::now() - start < 10s);

EXPECT_EQ(c1.load(), 1u);
EXPECT_EQ(c2.load(), 1u);
Expand Down
4 changes: 2 additions & 2 deletions rclcpp/test/rclcpp/test_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ TEST_F(TestSubscription, on_new_message_callback) {
auto increase_c1_cb = [&c1](size_t count_msgs) {c1 += count_msgs;};
sub->set_on_new_message_callback(increase_c1_cb);

auto pub = node->create_publisher<test_msgs::msg::Empty>("~/test_take", 1);
auto pub = node->create_publisher<test_msgs::msg::Empty>("~/test_take", 3);
{
test_msgs::msg::Empty msg;
pub->publish(msg);
Expand Down Expand Up @@ -500,7 +500,7 @@ TEST_F(TestSubscription, on_new_message_callback) {
start = std::chrono::steady_clock::now();
do {
std::this_thread::sleep_for(100ms);
} while (c3 == 0 && std::chrono::steady_clock::now() - start < 10s);
} while (c3 < 3 && std::chrono::steady_clock::now() - start < 10s);

EXPECT_EQ(c1.load(), 1u);
EXPECT_EQ(c2.load(), 1u);
Expand Down