Skip to content

Commit

Permalink
Adjusted spin_some test due to new behavior
Browse files Browse the repository at this point in the history
Previously would constantly trigger based on a 0ms delay timer;
now only evaluates a single timer once per spin_some call. Test
now adds multiple timers with a short delay to simulate performing
work.

Relies on behavior change from ros2/rclcpp#844, addressing
ros2/rclcpp#471

Distribution Statement A; OPSEC #2893

Signed-off-by: Roger Strain <rstrain@swri.org>
  • Loading branch information
Roger Strain committed Nov 20, 2019
1 parent 95680e7 commit ba87932
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions test_rclcpp/test/test_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <memory>
#include <stdexcept>
#include <string>
#include <vector>

#include "gtest/gtest.h"

Expand Down Expand Up @@ -59,11 +60,16 @@ TEST(CLASSNAME(test_executor, RMW_IMPLEMENTATION), spin_some_max_duration) {
if (!rclcpp::ok()) {rclcpp::init(0, nullptr);}
rclcpp::executors::SingleThreadedExecutor executor;
auto node = rclcpp::Node::make_shared("spin_some_max_duration");
auto timer = node->create_wall_timer(
0s,
[]() {
// Do nothing
});
auto lambda = []() {
std::this_thread::sleep_for(1ms);
};
std::vector<std::shared_ptr<rclcpp::WallTimer<decltype(lambda)>>> timers;
// creating 20 timers which will try to do 1 ms of work each
// only about 10ms worth of them should actually be performed
for (int i = 0; i < 20; i++) {
auto timer = node->create_wall_timer(0s, lambda);
timers.push_back(timer);
}
executor.add_node(node);

const auto max_duration = 10ms;
Expand Down

0 comments on commit ba87932

Please sign in to comment.