Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
210910794
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
210910794
Commits
53c2d600
Unverified
Commit
53c2d600
authored
4 years ago
by
BriceRenaudeau
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ServiceClient wait_for_service not infinite (#2278)
* change wait_for_service behavior * Add unit test
parent
aeccbe7a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nav2_util/include/nav2_util/service_client.hpp
+4
-10
4 additions, 10 deletions
nav2_util/include/nav2_util/service_client.hpp
nav2_util/test/test_service_client.cpp
+11
-0
11 additions, 0 deletions
nav2_util/test/test_service_client.cpp
with
15 additions
and
10 deletions
nav2_util/include/nav2_util/service_client.hpp
+
4
−
10
View file @
53c2d600
...
...
@@ -123,19 +123,13 @@ public:
}
/**
* @brief Block until a service is available
* @brief Block until a service is available
or timeout
* @param timeout Maximum timeout to wait for, default infinite
* @return bool true if service is available
*/
void
wait_for_service
(
const
std
::
chrono
::
nanoseconds
timeout
=
std
::
chrono
::
nanoseconds
::
max
())
bool
wait_for_service
(
const
std
::
chrono
::
nanoseconds
timeout
=
std
::
chrono
::
nanoseconds
::
max
())
{
auto
sleep_dur
=
std
::
chrono
::
milliseconds
(
10
);
while
(
!
client_
->
wait_for_service
(
timeout
))
{
if
(
!
rclcpp
::
ok
())
{
throw
std
::
runtime_error
(
service_name_
+
" service client: interrupted while waiting for service"
);
}
rclcpp
::
sleep_for
(
sleep_dur
);
}
return
client_
->
wait_for_service
(
timeout
);
}
protected
:
...
...
This diff is collapsed.
Click to expand it.
nav2_util/test/test_service_client.cpp
+
11
−
0
View file @
53c2d600
...
...
@@ -86,3 +86,14 @@ TEST(ServiceClient, can_ServiceClient_invoke_in_callback)
pub_thread
.
join
();
ASSERT_EQ
(
a
,
1
);
}
TEST
(
ServiceClient
,
can_ServiceClient_timeout
)
{
rclcpp
::
init
(
0
,
nullptr
);
auto
node
=
rclcpp
::
Node
::
make_shared
(
"test_node"
);
TestServiceClient
t
(
"bar"
,
node
);
rclcpp
::
spin_some
(
node
);
bool
ready
=
t
.
wait_for_service
(
std
::
chrono
::
milliseconds
(
10
));
rclcpp
::
shutdown
();
ASSERT_EQ
(
ready
,
false
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment