Skip to content

Commit

Permalink
Address request from #10771
Browse files Browse the repository at this point in the history
There was a request to add a timeout to the join in #10771.
The thread itself is unlikely to hang - more likely situation here
is the subscription failing to cause updates, causing the main
thread to hang forever on the condition variable. Added time outs
to both so we can have a bit more information about what actually
happened when the test completes.
  • Loading branch information
cecille committed Nov 1, 2021
1 parent 8dcf5d7 commit 4ff671b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/controller/python/test/test_scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,25 @@ def run(self):
# Reset the number of subscriptions received as subscribing causes a callback.
handler.subscriptionReceived = 0
changeThread.start()
subscriptionOK = True
with handler.cv:
while handler.subscriptionReceived < 5:
# We should observe 10 attribute changes
handler.cv.wait()
changeThread.join()
return True
# We should observe 5 attribute changes
# The changing thread will change the value after 3 seconds. If we're waiting more than 10, assume something
# is really wrong and bail out here with some information.
if not handler.cv.wait(10.0):
self.logger.error(f"Failed to receive subscription update")
subsciptionOk = False
break

# thread changes 5 times, and sleeps for 3 seconds in between. Add an additional 3 seconds of slack. Timeout is in seconds.
changeThread.join(18.0)
if changeThread.is_alive():
# Thread join timed out
self.logger.error(f"Failed to join change thread")
return False
return subsciptionOk

except Exception as ex:
self.logger.exception(f"Failed to finish API test: {ex}")
return False
Expand Down

0 comments on commit 4ff671b

Please sign in to comment.