Skip to content

Commit

Permalink
test-dds-device-discovery add a short sleep to avoid deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir committed Jan 15, 2025
1 parent 7c71487 commit a66a7c3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions unit-tests/dds/test-device-discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create_server_2( root ):

# We listen directly on the device-info topic
device_info_topic = dds.message.device_info.create_topic( participant, dds.topics.device_info )
device_info = dds.topic_reader( device_info_topic )
device_info_reader = dds.topic_reader( device_info_topic )
broadcast_received = threading.Event()
broadcast_devices = []
def on_device_info_available( reader ):
Expand All @@ -81,8 +81,8 @@ def on_device_info_available( reader ):
global broadcast_devices
broadcast_devices.append( j )
broadcast_received.set()
device_info.on_data_available( on_device_info_available )
device_info.run( dds.topic_reader.qos() )
device_info_reader.on_data_available( on_device_info_available )
device_info_reader.run( dds.topic_reader.qos() )

def detect_broadcast():
global broadcast_received, broadcast_devices
Expand Down Expand Up @@ -203,6 +203,9 @@ def __exit__( self, type, value, traceback ):
reader_2 = dds.topic_reader( device_info_topic )
reader_2.run( dds.topic_reader.qos() )
test.check_equal( len(broadcast_devices), 2 )
# Add short sleep to avoid a possible deadlock. Devices broadcast is handled by `on_device_info_available` callback,
# we may still be checking for messages (in eProcima reader thread) when trying to delete reader_2.
sleep( 0.1 )
del reader_2

#############################################################################################
Expand Down Expand Up @@ -300,7 +303,7 @@ def __exit__( self, type, value, traceback ):


del watcher
device_info.stop()
del device_info
device_info_reader.stop()
del device_info_reader
del participant
test.print_results_and_exit()

0 comments on commit a66a7c3

Please sign in to comment.