forked from ros2/launch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ReadyToTest action timeout using decorator (ros2#625)
* Added support for configurable timeout duration for ReadyToTest action using decorator Signed-off-by: deepanshu <[email protected]> Co-authored-by: Aditya <[email protected]>
- Loading branch information
1 parent
698e979
commit b0938dc
Showing
7 changed files
with
145 additions
and
1 deletion.
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
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
30 changes: 30 additions & 0 deletions
30
launch_testing/launch_testing/ready_to_test_action_timeout.py
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,30 @@ | ||
# Copyright 2022 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. | ||
|
||
|
||
def ready_to_test_action_timeout(timeout): | ||
""" | ||
Decorate a test launch description in a way that it adds ReadyToTest action timeout. | ||
attribute to the function being decorated. | ||
:param: timeout Duration for which the ReadyToTest action waits for processes to start up | ||
""" | ||
|
||
def _decorator(func): | ||
func.__ready_to_test_action_timeout__ = timeout | ||
return func | ||
|
||
return _decorator |
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
47 changes: 47 additions & 0 deletions
47
launch_testing/test/launch_testing/examples/ready_to_test_action_timeout_test.py
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,47 @@ | ||
# Copyright 2022 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. | ||
|
||
import unittest | ||
|
||
import launch | ||
from launch.actions import TimerAction | ||
import launch_testing | ||
from launch_testing.actions import ReadyToTest | ||
|
||
import pytest | ||
|
||
|
||
# The ReadyToTest action waits for 15 second by default for the processes to | ||
# start, if processes take more time an error is thrown. We use decorator here | ||
# to provide timeout duration of 20 second so that processes that take longer than | ||
# 15 seconds can start up. | ||
|
||
@pytest.mark.launch_test | ||
@launch_testing.ready_to_test_action_timeout(20) | ||
def generate_test_description(): | ||
# takes 15 sec for the TimerAction process to start | ||
return launch.LaunchDescription([ | ||
launch_testing.util.KeepAliveProc(), | ||
TimerAction(period=15.0, actions=[ReadyToTest()]), | ||
]) | ||
|
||
|
||
# the process should exit cleanly now since the process takes 15 second | ||
# to start and timeout duration of ReadyToTest action is 20 seconds. | ||
@launch_testing.post_shutdown_test() | ||
class TestHelloWorldShutdown(unittest.TestCase): | ||
|
||
def test_exit_codes(self, proc_info): | ||
"""Check if the processes exited normally.""" | ||
launch_testing.asserts.assertExitCodes(proc_info) |
49 changes: 49 additions & 0 deletions
49
launch_testing/test/launch_testing/test_ready_to_test_action_decorator.py
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,49 @@ | ||
# Copyright 2022 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. | ||
|
||
import launch_testing | ||
|
||
|
||
def test_ready_to_test_action_attribute(): | ||
|
||
@launch_testing.ready_to_test_action_timeout(10) | ||
def fake_test_description(arg): | ||
pass # pragma: no cover | ||
|
||
assert hasattr(fake_test_description, '__ready_to_test_action_timeout__') | ||
assert getattr(fake_test_description, '__ready_to_test_action_timeout__') == 10 | ||
|
||
|
||
def test_parametrize_and_ready_to_test_action_attribute(): | ||
|
||
@launch_testing.parametrize('val', [1, 2, 3]) | ||
@launch_testing.ready_to_test_action_timeout(10) | ||
def fake_test_description(arg): | ||
pass # pragma: no cover | ||
|
||
assert hasattr(fake_test_description, '__parametrized__') | ||
assert hasattr(fake_test_description, '__ready_to_test_action_timeout__') | ||
assert getattr(fake_test_description, '__ready_to_test_action_timeout__') == 10 | ||
|
||
|
||
def test_ready_to_test_action_and_parametrize_attribute(): | ||
|
||
@launch_testing.ready_to_test_action_timeout(10) | ||
@launch_testing.parametrize('val', [1, 2, 3]) | ||
def fake_test_description(arg): | ||
pass # pragma: no cover | ||
|
||
assert hasattr(fake_test_description, '__parametrized__') | ||
assert hasattr(fake_test_description, '__ready_to_test_action_timeout__') | ||
assert getattr(fake_test_description, '__ready_to_test_action_timeout__') == 10 |