launch_test does not return and shows ValueError: generator already executing

Aperta
#636 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
testing

Direzione di ricerca

Inizia da test/test_service_member_function.py e dall’invocazione di launch_test, quindi esamina le chiamate a rclpy.spin e la configurazione del client di servizio mostrata nel report. Riproduci l’errore del generatore con i test dei servizi elencati e determina il modo previsto per eseguire tutti i servizi senza blocchi; il lavoro è completato quando il comando di test termina senza il ValueError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I am trying to run a test using launch_test but it shows "ValueError: generator already executing". In this case, the launch_test does not return. Therefore, I have to terminate the process by pressing Ctrl + C. Below is the complete info reported at terminal:

$ launch_test src/minimal_service/test/test_service_member_function.py 
[INFO] [launch]: All log files can be found below /home/ravi/.ros/log/2022-08-01-19-42-08-016668-dell-96224
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [service_member_function-1]: process started with pid [96228]
test_srv_1 (test_service_member_function.TestMinimalServiceNode) ... ok
test_srv_1_exists (test_service_member_function.TestMinimalServiceNode) ... [WARN] [1659350528.358283962] [rcl.logging_rosout]: Publisher already registered for provided node name. If this is due to multiple nodes with the same name then all logs for that logger name will go out over the existing publisher. As soon as any node with that name is destructed it will unregister the publisher, preventing any further logs for that name from being published on the rosout topic.
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
ok
test_srv_2 (test_service_member_function.TestMinimalServiceNode) ...     self._target(*self._args, **self._kwargs)
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    executor.spin_once()
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
    self._target(*self._args, **self._kwargs)
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
    return next(self._cb_iter)
ValueError: generator already executing
    executor.spin_once()
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
    handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
    return next(self._cb_iter)
ValueError: generator already executing
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[service_member_function-1] Traceback (most recent call last):
[service_member_function-1]   File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/examples_rclpy_minimal_service/service_member_function", line 33, in <module>
[service_member_function-1]     sys.exit(load_entry_point('examples-rclpy-minimal-service==0.9.4', 'console_scripts', 'service_member_function')())
[service_member_function-1]   File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/python3.8/site-packages/examples_rclpy_minimal_service/service_member_function.py", line 31, in main
[service_member_function-1]     rclpy.spin(node)
[service_member_function-1]   File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
[service_member_function-1]     executor.spin_once()
[service_member_function-1]   File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
[service_member_function-1]     handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
[service_member_function-1]   File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
[service_member_function-1]     return next(self._cb_iter)
[service_member_function-1]   File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 588, in _wait_for_ready_callbacks
[service_member_function-1]     wait_set.wait(timeout_nsec)
[service_member_function-1] KeyboardInterrupt
[ERROR] [service_member_function-1]: process has died [pid 96228, exit code -2, cmd '/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/examples_rclpy_minimal_service/service_member_function --ros-args -r __ns:=/'].
Processes under test stopped before tests completed
Process 'service_member_function-1' exited with -2
##### 'service_member_function-1' output #####
Traceback (most recent call last):
  File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/examples_rclpy_minimal_service/service_member_function", line 33, in <module>
    sys.exit(load_entry_point('examples-rclpy-minimal-service==0.9.4', 'console_scripts', 'service_member_function')())
  File "/home/ravi/ros2_ws/install/examples_rclpy_minimal_service/lib/python3.8/site-packages/examples_rclpy_minimal_service/service_member_function.py", line 31, in main
    rclpy.spin(node)
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/__init__.py", line 196, in spin
    executor.spin_once()
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 704, in spin_once
    handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 690, in wait_for_ready_callbacks
    return next(self._cb_iter)
  File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py", line 588, in _wait_for_ready_callbacks
    wait_set.wait(timeout_nsec)
KeyboardInterrupt
##############################################

Required Info:

  • Operating System:
    • Ubuntu 20.04.4 LTS
  • Installation type:
    • binaries
  • DDS implementation:
    • default
  • Client library (if applicable):
    • rclpy

Question

How to test all the services in my node?

Code

  • test_service_member_function.py
    from threading import Thread
    import unittest
    
    import launch
    import launch_ros
    import launch_testing
    import pytest
    import rclpy
    from std_srvs.srv import SetBool, Trigger
    from example_interfaces.srv import AddTwoInts as AddTwoI
    
    
    @pytest.mark.rostest
    def generate_test_description():
        node = launch_ros.actions.Node(
            package='examples_rclpy_minimal_service',
            namespace='',
            executable='service_member_function',
        )
        return (
            launch.LaunchDescription(
                [
                    node,
                    # Start tests right away - no need to wait for anything
                    launch_testing.actions.ReadyToTest(),
                ]
            ),
            {
                'minimal_service_node': node,
            },
        )
    
    
    class TestMinimalServiceNode(unittest.TestCase):
    
        @classmethod
        def setUpClass(cls):
            # Initialize the ROS context for the test node
            rclpy.init()
    
        @classmethod
        def tearDownClass(cls):
            # Shutdown the ROS context
            rclpy.shutdown()
    
        def setUp(self):
            # Create a ROS node for tests
            self.node = rclpy.create_node('test_minimal_service_node')
    
            # Creating service clients
            self.client_1 = self.node.create_client(AddTwoI, 'srv_1')
            self.client_2 = self.node.create_client(SetBool, 'srv_2')
            self.client_3 = self.node.create_client(Trigger, 'srv_3')
    
            self.assertTrue(self.client_1.wait_for_service(timeout_sec=5.0))
    
            # Create a spin thread for synchronous service call
            self.spin_thread = Thread(target=rclpy.spin, args=(self.node,))
            self.spin_thread.start()
    
        def tearDown(self):
            self.node.destroy_node()
    
        def test_srv_1_exists(self):
            self.assertTrue(self.client_1.wait_for_service(timeout_sec=5.0))
    
        def test_srv_2_exists(self):
            self.assertTrue(self.client_2.wait_for_service(timeout_sec=5.0))
    
        def test_srv_3_exists(self):
            self.assertTrue(self.client_3.wait_for_service(timeout_sec=5.0))
    
        def test_srv_1(self):
            req = AddTwoI.Request(a=10, b=20)
            res = self.client_1.call(req)
            self.assertEqual(res.sum, 30)
    
        def test_srv_2(self):
            req = SetBool.Request(data=True)
            res = self.client_2.call(req)
            self.assertEqual(res.message, 'Hello from SetBool Service')
    
        def test_srv_3(self):
            req = Trigger.Request()
            res = self.client_3.call(req)
            self.assertEqual(res.message, 'Hello from Trigger Service')
    ```
    
  • service_member_function.py
    import rclpy
    from rclpy.node import Node
    from std_srvs.srv import SetBool, Trigger
    from example_interfaces.srv import AddTwoInts as AddTwoI
    
    
    class MinimalService(Node):
    
        def __init__(self):
            super().__init__('minimal_service')
            self.srv_1 = self.create_service(AddTwoI, 'srv_1', self.srv_1_cb)
            self.srv_2 = self.create_service(SetBool, 'srv_2', self.srv_2_cb)
            self.srv_3 = self.create_service(Trigger, 'srv_3', self.srv_3_cb)
    
        def srv_1_cb(self, req, res):
            res.sum = req.a + req.b
            return res
    
        def srv_2_cb(self, req, res):
            res.message = 'Hello from SetBool Service'
            return res
    
        def srv_3_cb(self, req, res):
            res.message = 'Hello from Trigger Service'
            return res
    
    
    def main(args=None):
        rclpy.init(args=args)
        node = MinimalService()
        rclpy.spin(node)
        rclpy.shutdown()
    
    
    if __name__ == '__main__':
        main()
    

Additional Info

Please note that all the services returns peacefully when called from terminal using ros2 service call .... Anyway, below is the workspace structure:

.
├── build
├── install
├── log
└── src
    └── minimal_service
        ├── CHANGELOG.rst
        ├── examples_rclpy_minimal_service
        │   ├── __init__.py
        │   ├── service_member_function.py
        │   └── service.py
        ├── package.xml
        ├── README.md
        ├── resource
        │   └── examples_rclpy_minimal_service
        ├── setup.cfg
        ├── setup.py
        └── test
            ├── test_copyright.py
            ├── test_flake8.py
            ├── test_pep257.py
            └── test_service_member_function.py

The package minimal_service has been taken from ros2/examples.

Lingua principale
Python
Stelle
156
Fork
200
Merge medio
2g 11h
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ros2/launch

Tutte le issue di ros2/launch

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.