Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverted WaitForTopics utility usage #326

Merged
merged 3 commits into from
Oct 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from threading import Event
from threading import Thread
import unittest

import launch
import launch.actions
import launch_ros.actions
import launch_testing.actions
import launch_testing.markers
from launch_testing_ros import WaitForTopics
import pytest
import rclpy
from rclpy.node import Node
from std_msgs.msg import String


Expand All @@ -39,6 +42,33 @@ def generate_test_description():

class TestFixture(unittest.TestCase):

def test_check_if_msgs_published(self):
with WaitForTopics([('chatter', String)], timeout=5.0):
print('Topic received messages !')
def test_check_if_msgs_published(self, proc_output):
rclpy.init()
node = DummyNode('test_node')
node.start_subscriber()
msgs_received_flag = node.msg_event_object.wait(timeout=5.0)
assert msgs_received_flag, 'Did not receive msgs !'
rclpy.shutdown()


class DummyNode(Node):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this WaitForTopics.

If you prefer, we can leave the test above unchanged and just copy the entire WaitForTopics from ros2/launch_ros#274 here.

Either way, we should add a comment TODO here to move the implementation back to launch_ros after ros2/rclpy#831 is resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved entire implementation, added a TODO comment


def __init__(self, name='test_node'):
super().__init__(name)
self.msg_event_object = Event()

def start_subscriber(self):
# Create a subscriber
self.subscription = self.create_subscription(
String,
'chatter',
self.subscriber_callback,
10
)

# Add a spin thread
self.ros_spin_thread = Thread(target=lambda node: rclpy.spin(node), args=(self,))
self.ros_spin_thread.start()

def subscriber_callback(self, data):
self.msg_event_object.set()