-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use wait_for_service to make Service tests less flaky (#132)
* use wait_for_service to make tests less flaky * realign timeouts * avoid using wait_for_service with fastrtps this can be undone once fastrtps supports wait_for_service * [test_communication] avoid wait_for_service with fastrtps it can be undone once fastrtps supports wait_for_service * add test to ensure wait_for_service wakes after shutdown/sigint
- Loading branch information
Showing
10 changed files
with
180 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test_rclcpp/test/test_client_wait_for_service_shutdown.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2016 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <chrono> | ||
#include <string> // TODO(wjwwood): remove me when fastrtps exclusion is removed | ||
#include <thread> | ||
|
||
#include "gtest/gtest.h" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "rmw/rmw.h" // TODO(wjwwood): remove me when fastrtps exclusion is removed | ||
#include "test_rclcpp/srv/add_two_ints.hpp" | ||
|
||
#ifdef RMW_IMPLEMENTATION | ||
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX | ||
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) | ||
#else | ||
# define CLASSNAME(NAME, SUFFIX) NAME | ||
#endif | ||
|
||
// rclcpp::shutdown() should wake up wait_for_service, even without spin. | ||
TEST(CLASSNAME(service_client, RMW_IMPLEMENTATION), wait_for_service_shutdown) { | ||
// TODO(wjwwood): remove this "skip" when fastrtps supports wait_for_service. | ||
if (std::string(rmw_get_implementation_identifier()) == "rmw_fastrtps_cpp") { | ||
return; | ||
} | ||
rclcpp::init(0, nullptr); | ||
auto node = rclcpp::node::Node::make_shared("wait_for_service_shutdown"); | ||
|
||
auto client = node->create_client<test_rclcpp::srv::AddTwoInts>("wait_for_service_shutdown"); | ||
|
||
auto shutdown_thread = std::thread([]() { | ||
std::this_thread::sleep_for(1_s); | ||
rclcpp::shutdown(); | ||
}); | ||
auto start = std::chrono::steady_clock::now(); | ||
client->wait_for_service(15_s); | ||
auto end = std::chrono::steady_clock::now(); | ||
ASSERT_LE(end - start, 10_s); | ||
shutdown_thread.join(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.