-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add stealth mode for topic_tools/relay (#1155)
- Loading branch information
1 parent
6bb5446
commit 34d0237
Showing
4 changed files
with
123 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<launch> | ||
<node name="topic_pub" pkg="rostopic" type="rostopic" | ||
args="pub -r 10 /original_topic std_msgs/String foo" /> | ||
<node name="topic_relay" pkg="topic_tools" type="relay" | ||
args="/original_topic /original_topic/relay"> | ||
<rosparam> | ||
lazy: true | ||
</rosparam> | ||
</node> | ||
<test test-name="test_relay_stealth" | ||
pkg="topic_tools" type="test_relay_stealth.py" /> | ||
|
||
<node name="relay_stealth" pkg="topic_tools" type="relay" | ||
args="/original_topic/relay /relay_stealth/output" | ||
output="screen"> | ||
<rosparam> | ||
stealth: true | ||
monitor_topic: /original_topic/relay | ||
</rosparam> | ||
</node> | ||
</launch> |
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,45 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import rospy | ||
import unittest | ||
from std_msgs.msg import String | ||
|
||
|
||
class TestRelayStealth(unittest.TestCase): | ||
def out_callback(self, msg): | ||
self.out_msg_count += 1 | ||
|
||
def monitor_callback(self, msg): | ||
self.monitor_msg_count += 1 | ||
|
||
def test_stealth_relay(self): | ||
self.out_msg_count = 0 | ||
self.monitor_msg_count = 0 | ||
sub_out = rospy.Subscriber("/relay_stealth/output", String, | ||
self.out_callback, queue_size=1) | ||
for i in range(5): | ||
if sub_out.get_num_connections() == 0: | ||
rospy.sleep(1) | ||
self.assertTrue(sub_out.get_num_connections() > 0) | ||
|
||
rospy.sleep(5) | ||
self.assertEqual(self.out_msg_count, 0) | ||
|
||
sub_monitor = rospy.Subscriber("/original_topic/relay", String, | ||
self.monitor_callback, queue_size=1) | ||
rospy.sleep(5) | ||
self.assertGreater(self.monitor_msg_count, 0) | ||
self.assertGreater(self.out_msg_count, 0) | ||
|
||
cnt = self.out_msg_count | ||
sub_monitor.unregister() | ||
|
||
rospy.sleep(3) | ||
self.assertLess(abs(cnt - self.out_msg_count), 30) | ||
|
||
|
||
if __name__ == '__main__': | ||
import rostest | ||
rospy.init_node("test_relay_stealth") | ||
rostest.rosrun("topic_tools", "test_relay_stealth", TestRelayStealth) |