Skip to content

Commit

Permalink
[CI] Make it possible to specify the timeout when waiting for a speci…
Browse files Browse the repository at this point in the history
…fic string in scripts/tests/chiptest/test_definition.py since it may be longer than 10 seconds
  • Loading branch information
vivien-apple committed Feb 2, 2024
1 parent b1bf11e commit cbbb006
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import xmlrpc.client

_DEFAULT_KEY = 'default'
_DEFAULT_WAIT_FOR_MESSAGE_TIMEOUT_SECONDS = 10
_IP = '127.0.0.1'
_PORT = 9000

Expand Down Expand Up @@ -113,9 +114,11 @@ def factoryReset(request):
def waitForMessage(request):
register_key = _get_option(request, 'registerKey', _DEFAULT_KEY)
message = _get_option(request, 'message')
timeout_in_seconds = _get_option(
request, 'timeoutInSeconds', _DEFAULT_WAIT_FOR_MESSAGE_TIMEOUT_SECONDS)

with xmlrpc.client.ServerProxy(_make_url(), allow_none=True) as proxy:
proxy.waitForMessage(register_key, [message])
proxy.waitForMessage(register_key, [message], timeout_in_seconds)

def createOtaImage(request):
otaImageFilePath = _get_option(request, 'otaImageFilePath')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<command source="client" code="3" name="WaitForMessage">
<arg name="registerKey" type="char_string"/>
<arg name="message" type="char_string"/>
<arg name="timeoutInSeconds" type="int16u" optional="true"/>
</command>
</cluster>
</configurator>
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/chiptest/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ def factoryReset(self, name):
return accessory.factoryReset()
return False

def waitForMessage(self, name, message):
def waitForMessage(self, name, message, timeoutInSeconds=10):
accessory = self.__accessories[name]
if accessory:
# The message param comes directly from the sys.argv[2:] of WaitForMessage.py and should contain a list of strings that
# comprise the entire message to wait for
return accessory.waitForMessage(' '.join(message))
return accessory.waitForMessage(' '.join(message), timeoutInSeconds)
return False

def createOtaImage(self, otaImageFilePath, rawImageFilePath, rawImageContent, vid='0xDEAD', pid='0xBEEF'):
Expand Down
8 changes: 4 additions & 4 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def factoryReset(self):
def waitForAnyAdvertisement(self):
self.__waitFor("mDNS service published:", self.process, self.outpipe)

def waitForMessage(self, message):
self.__waitFor(message, self.process, self.outpipe)
def waitForMessage(self, message, timeoutInSeconds = 10):
self.__waitFor(message, self.process, self.outpipe, timeoutInSeconds)
return True

def kill(self):
Expand Down Expand Up @@ -124,7 +124,7 @@ def __startServer(self, runner, command):
self.kvsPathSet.add(value)
return runner.RunSubprocess(app_cmd, name='APP ', wait=False)

def __waitFor(self, waitForString, server_process, outpipe):
def __waitFor(self, waitForString, server_process, outpipe, timeoutInSeconds=10):
logging.debug('Waiting for %s' % waitForString)

start_time = time.monotonic()
Expand All @@ -139,7 +139,7 @@ def __waitFor(self, waitForString, server_process, outpipe):
(waitForString, server_process.returncode))
logging.error(died_str)
raise Exception(died_str)
if time.monotonic() - start_time > 10:
if time.monotonic() - start_time > timeoutInSeconds:
raise Exception('Timeout while waiting for %s' % waitForString)
time.sleep(0.1)
ready, self.lastLogIndex = outpipe.CapturedLogContains(
Expand Down

0 comments on commit cbbb006

Please sign in to comment.