Exemplo n.º 1
0
 def test_use_and_free_capability(self):
     assert wait_for_capability_server(10)
     c = CapabilitiesClient()
     c.wait_for_services(timeout=3.0)
     # Give invalid bond id to use_capability
     with assert_raises(ServiceException):
         call_service('/capability_server/use_capability',
                      'minimal_pkg/Minimal', '', 'invalid_bond_id')
     # Try to use a non-existent cap
     with assert_raises(ServiceException):
         c.use_capability('not_a_pkg/NotACap')
     # Use cap and wait for it to be running
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
     # Try to use it with a different provider
     with assert_raises(ServiceException):
         c.use_capability('minimal_pkg/Minimal',
                          'minimal_pkg/specific_minimal')
     # Use it a second time, free it once, assert it is stil there
     c.use_capability('minimal_pkg/Minimal')
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'],
                                        tries=5)
     assert sorted(result) != sorted(expected), (sorted(result),
                                                 sorted(expected))
     # Directly call ~free_capability with an invalid bond_id
     with assert_raises(ServiceException):
         call_service('/capability_server/free_capability',
                      'minimal_pkg/Minimal', 'invalid_bond_id')
     # Free it again and assert it goes down
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
     # Try to over free it and get an exception
     with assert_raises(ServiceException):
         c.free_capability('minimal_pkg/Minimal')
     # Use it again, then break the bond and assert it goes down because of that
     c.use_capability('minimal_pkg/Minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
     c._bond.break_bond()
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
 def test_default_provider(self):
     assert wait_for_capability_server(10)
     call_service('/capability_server/start_capability', 'no_default_provider_pkg/Minimal', '')
     rospy.sleep(1)  # Wait for the system to settle
     resp = call_service('/capability_server/get_running_capabilities')
     result = [x.capability.provider for x in resp.running_capabilities]
     retry_count = 0
     while not result:
         retry_count += 1
         if retry_count == 10:
             break
         # Retry, sometimes the system is really slow...
         rospy.sleep(1)
         resp = call_service('/capability_server/get_running_capabilities')
         result = [x.capability.provider for x in resp.running_capabilities]
     expected = ['no_default_provider_pkg/minimal']
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
Exemplo n.º 3
0
def wait_for_result_to_happen(expected, initial_result, tries=10, sleep_period=1):
    result = initial_result
    count = 0
    while count != tries and sorted(result) != sorted(expected):
        rospy.sleep(sleep_period)
        count += 1
        resp = call_service('/capability_server/get_running_capabilities')
        result = [x.capability.capability for x in resp.running_capabilities]
    return result
Exemplo n.º 4
0
 def test_use_and_free_capability(self):
     assert wait_for_capability_server(10)
     c = CapabilitiesClient()
     c.wait_for_services(timeout=3.0)
     # Give invalid bond id to use_capability
     with assert_raises(ServiceException):
         call_service('/capability_server/use_capability', 'minimal_pkg/Minimal', '', 'invalid_bond_id')
     # Try to use a non-existent cap
     with assert_raises(ServiceException):
         c.use_capability('not_a_pkg/NotACap')
     # Use cap and wait for it to be running
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     # Try to use it with a different provider
     with assert_raises(ServiceException):
         c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/specific_minimal')
     # Use it a second time, free it once, assert it is stil there
     c.use_capability('minimal_pkg/Minimal')
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'], tries=5)
     assert sorted(result) != sorted(expected), (sorted(result), sorted(expected))
     # Directly call ~free_capability with an invalid bond_id
     with assert_raises(ServiceException):
         call_service('/capability_server/free_capability', 'minimal_pkg/Minimal', 'invalid_bond_id')
     # Free it again and assert it goes down
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     # Try to over free it and get an exception
     with assert_raises(CapabilityNotRunningException):
         c.free_capability('minimal_pkg/Minimal')
     # Use it again, then break the bond and assert it goes down because of that
     c.use_capability('minimal_pkg/Minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     c._bond.break_bond()
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
Exemplo n.º 5
0
 def test_default_provider(self):
     wait_for_capability_server(None)
     call_service('/capability_server/start_capability',
                  'no_default_provider_pkg/Minimal', '')
     rospy.sleep(1)  # Wait for the system to settle
     resp = call_service('/capability_server/get_running_capabilities')
     result = [x.capability.provider for x in resp.running_capabilities]
     retry_count = 0
     while not result:
         retry_count += 1
         if retry_count == 10:
             break
         # Retry, sometimes the system is really slow...
         rospy.sleep(1)
         resp = call_service('/capability_server/get_running_capabilities')
         result = [x.capability.provider for x in resp.running_capabilities]
     expected = ['no_default_provider_pkg/minimal']
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
Exemplo n.º 6
0
def wait_for_result_to_happen(expected,
                              initial_result,
                              tries=10,
                              sleep_period=1):
    result = initial_result
    count = 0
    while count != tries and sorted(result) != sorted(expected):
        rospy.sleep(sleep_period)
        count += 1
        resp = call_service('/capability_server/get_running_capabilities')
        result = [x.capability.capability for x in resp.running_capabilities]
    return result
Exemplo n.º 7
0
 def test_remapping(self):
     with assert_raises(ServiceException):
         call_service('/capability_server/get_remappings', 'robot_base_pkg/FrontDistance')
     call_service('/capability_server/start_capability', 'robot_base_pkg/FrontDistance', '')
     resp = call_service('/capability_server/get_remappings', 'robot_base_pkg/FrontDistance')
     assert len(resp.topics) == 1, resp
     assert ('front/distance', 'robot/front/distance') in [(t.key, t.value) for t in resp.topics], resp
     resp = call_service('/capability_server/get_remappings', 'robot_base_pkg/front_distance')
     assert resp.topics, resp
     assert ('front/distance', 'robot/front/distance') in [(t.key, t.value) for t in resp.topics], resp
     resp = call_service('/capability_server/get_remappings', 'robot_base_pkg/Distance')
     assert resp.topics, resp
     assert ('distance', 'robot/front/distance') in [(t.key, t.value) for t in resp.topics], resp
 def test_stop_base_capability(self):
     """
     Stopping a base capability should stop all dependent capabilities too.
     """
     call_service('/capability_server/start_capability',
                  'navigation_capability/Navigation',
                  'navigation_capability/faux_navigation')
     rospy.sleep(6)  # Wait for the system to settle
     resp = call_service('/capability_server/get_running_capabilities')
     result = [x.capability.capability for x in resp.running_capabilities]
     expected = ['navigation_capability/Navigation',
                 'differential_mobile_base_capability/DifferentialMobileBase']
     self.assertEqual(sorted(result), sorted(expected))
     call_service('/capability_server/stop_capability',
                  'differential_mobile_base_capability/DifferentialMobileBase')
     resp = call_service('/capability_server/get_running_capabilities')
     # The list of running capabilities should be empty
     self.assertEqual([], resp.running_capabilities)
Exemplo n.º 9
0
 def test_stop_base_capability(self):
     """
     Stopping a base capability should stop all dependent capabilities too.
     """
     call_service('/capability_server/start_capability',
                  'navigation_capability/Navigation',
                  'navigation_capability/faux_navigation')
     rospy.sleep(6)  # Wait for the system to settle
     resp = call_service('/capability_server/get_running_capabilities')
     result = [x.capability.capability for x in resp.running_capabilities]
     expected = [
         'navigation_capability/Navigation',
         'differential_mobile_base_capability/DifferentialMobileBase'
     ]
     self.assertEqual(sorted(result), sorted(expected))
     call_service(
         '/capability_server/stop_capability',
         'differential_mobile_base_capability/DifferentialMobileBase')
     resp = call_service('/capability_server/get_running_capabilities')
     # The list of running capabilities should be empty
     self.assertEqual([], resp.running_capabilities)
 def test_stop_base_capability(self):
     """
     Stopping a base capability should stop all dependent capabilities too.
     """
     wait_for_capability_server(10)
     call_service('/capability_server/start_capability',
                  'navigation_capability/Navigation',
                  'navigation_capability/faux_navigation')
     result = []
     expected = ['navigation_capability/Navigation',
                 'differential_mobile_base_capability/DifferentialMobileBase']
     count = 0
     while count != 10 and sorted(result) != sorted(expected):
         rospy.sleep(1)
         count += 1
         resp = call_service('/capability_server/get_running_capabilities')
         result = [x.capability.capability for x in resp.running_capabilities]
     self.assertEqual(sorted(result), sorted(expected))
     call_service('/capability_server/stop_capability',
                  'differential_mobile_base_capability/DifferentialMobileBase')
     resp = call_service('/capability_server/get_running_capabilities')
     # The list of running capabilities should be empty
     self.assertEqual([], resp.running_capabilities)
 def test_start_stop_dependent_capabilities(self):
     call_service('/capability_server/start_capability',
                  'navigation_capability/Navigation',
                  'navigation_capability/faux_navigation')
     rospy.sleep(6)  # Wait for the system to settle
     resp = call_service('/capability_server/get_running_capabilities')
     result = [x.capability.capability for x in resp.running_capabilities]
     if not result:
         # Retry, sometimes the system is really slow...
         rospy.sleep(6)
         resp = call_service('/capability_server/get_running_capabilities')
         result = [x.capability.capability for x in resp.running_capabilities]
     expected = ['navigation_capability/Navigation',
                 'differential_mobile_base_capability/DifferentialMobileBase']
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     call_service('/capability_server/start_capability',
                  'minimal_pkg/Minimal',
                  'minimal_pkg/minimal')
     rospy.sleep(1)
     call_service('/capability_server/stop_capability',
                  'minimal_pkg/Minimal')
     rospy.sleep(2)
     call_service('/capability_server/stop_capability', 'navigation_capability/Navigation')
     rospy.sleep(1)  # Wait for the system to shutdown, so coverage can work
     # fail to call provider with invalid dependent provider
     with assert_raises(ServiceException):
         call_service('/capability_server/start_capability',
                      'navigation_capability/Navigation',
                      'navigation_capability/faux_navigation_invalid_preferred_provider')
Exemplo n.º 12
0
 def test_start_stop_dependent_capabilities(self):
     call_service('/capability_server/start_capability',
                  'navigation_capability/Navigation',
                  'navigation_capability/faux_navigation')
     rospy.sleep(6)  # Wait for the system to settle
     resp = call_service('/capability_server/get_running_capabilities')
     result = [x.capability.capability for x in resp.running_capabilities]
     if not result:
         # Retry, sometimes the system is really slow...
         rospy.sleep(6)
         resp = call_service('/capability_server/get_running_capabilities')
         result = [
             x.capability.capability for x in resp.running_capabilities
         ]
     expected = [
         'navigation_capability/Navigation',
         'differential_mobile_base_capability/DifferentialMobileBase'
     ]
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
     call_service('/capability_server/start_capability',
                  'minimal_pkg/Minimal', 'minimal_pkg/minimal')
     rospy.sleep(1)
     call_service('/capability_server/stop_capability',
                  'minimal_pkg/Minimal')
     rospy.sleep(2)
     call_service('/capability_server/stop_capability',
                  'navigation_capability/Navigation')
     rospy.sleep(1)  # Wait for the system to shutdown, so coverage can work
     # fail to call provider with invalid dependent provider
     with assert_raises(ServiceException):
         call_service(
             '/capability_server/start_capability',
             'navigation_capability/Navigation',
             'navigation_capability/faux_navigation_invalid_preferred_provider'
         )
 def test_start_stop_dependent_capabilities(self):
     wait_for_capability_server(10)
     call_service('/capability_server/start_capability',
                  'navigation_capability/Navigation',
                  'navigation_capability/faux_navigation')
     expected = ['navigation_capability/Navigation',
                 'differential_mobile_base_capability/DifferentialMobileBase']
     result = []
     count = 0
     while count != 10 and sorted(result) != sorted(expected):
         rospy.sleep(1)
         count += 1
         resp = call_service('/capability_server/get_running_capabilities')
         result = [x.capability.capability for x in resp.running_capabilities]
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     call_service('/capability_server/start_capability',
                  'minimal_pkg/Minimal',
                  'minimal_pkg/minimal')
     rospy.sleep(1)
     call_service('/capability_server/stop_capability',
                  'minimal_pkg/Minimal')
     rospy.sleep(2)
     call_service('/capability_server/stop_capability', 'navigation_capability/Navigation')
     rospy.sleep(1)  # Wait for the system to shutdown, so coverage can work
     # fail to call provider with invalid dependent provider
     with assert_raises(ServiceException):
         call_service('/capability_server/start_capability',
                      'navigation_capability/Navigation',
                      'navigation_capability/faux_navigation_invalid_preferred_provider')