Add more tests and more test utils
This commit is contained in:
		
							parent
							
								
									20cf197b87
								
							
						
					
					
						commit
						eb8a7e2c26
					
				
					 10 changed files with 389 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -24,14 +24,60 @@ class TestSubscription(TraceTestCase):
 | 
			
		|||
            *args,
 | 
			
		||||
            session_name_prefix='session-test-subscription-creation',
 | 
			
		||||
            events_ros=[
 | 
			
		||||
                'ros2:rcl_node_init',
 | 
			
		||||
                'ros2:rcl_subscription_init',
 | 
			
		||||
                'ros2:rclcpp_subscription_callback_added',
 | 
			
		||||
            ],
 | 
			
		||||
            nodes=['test_subscription']
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_creation(self):
 | 
			
		||||
        pass
 | 
			
		||||
    def test_all(self):
 | 
			
		||||
        # Check events order as set (e.g. sub_init before callback_added)
 | 
			
		||||
        self.assertEventsOrderSet(self._events_ros)
 | 
			
		||||
 | 
			
		||||
        # Check fields
 | 
			
		||||
        sub_init_events = self.get_events_with_name('ros2:rcl_subscription_init')
 | 
			
		||||
        for event in sub_init_events:
 | 
			
		||||
            self.assertValidHandle(
 | 
			
		||||
                event,
 | 
			
		||||
                ['subscription_handle', 'node_handle', 'rmw_subscription_handle'])
 | 
			
		||||
            self.assertValidQueueDepth(event, 'queue_depth')
 | 
			
		||||
            self.assertStringFieldNotEmpty(event, 'topic_name')
 | 
			
		||||
 | 
			
		||||
        callback_added_events = self.get_events_with_name('ros2:rclcpp_subscription_callback_added')
 | 
			
		||||
        for event in callback_added_events:
 | 
			
		||||
            self.assertValidHandle(event, ['subscription_handle', 'callback'])
 | 
			
		||||
 | 
			
		||||
        # Check that the test topic name exists
 | 
			
		||||
        test_sub_init_events = self.get_events_with_field_value(
 | 
			
		||||
            'topic_name',
 | 
			
		||||
            '/the_topic',
 | 
			
		||||
            sub_init_events)
 | 
			
		||||
        self.assertEqual(len(test_sub_init_events), 1, 'cannot find test topic name')
 | 
			
		||||
        test_sub_init_event = test_sub_init_events[0]
 | 
			
		||||
 | 
			
		||||
        # Check that the node handle matches the node_init event
 | 
			
		||||
        node_init_events = self.get_events_with_name('ros2:rcl_node_init')
 | 
			
		||||
        test_sub_node_init_events = self.get_events_with_procname(
 | 
			
		||||
            'test_subscription',
 | 
			
		||||
            node_init_events)
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            len(test_sub_node_init_events),
 | 
			
		||||
            1,
 | 
			
		||||
            'none or more than 1 node_init event')
 | 
			
		||||
        test_sub_node_init_event = test_sub_node_init_events[0]
 | 
			
		||||
        self.assertMatchingField(
 | 
			
		||||
            test_sub_node_init_event,
 | 
			
		||||
            'node_handle',
 | 
			
		||||
            'ros2:rcl_subscription_init',
 | 
			
		||||
            sub_init_events)
 | 
			
		||||
 | 
			
		||||
        # Check that subscription handle matches with callback_added event
 | 
			
		||||
        self.assertMatchingField(
 | 
			
		||||
            test_sub_init_event,
 | 
			
		||||
            'subscription_handle',
 | 
			
		||||
            None,
 | 
			
		||||
            callback_added_events)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue