Skip to content

Commit

Permalink
Make Tests job fail quickly instead of timing out on discovery failur…
Browse files Browse the repository at this point in the history
…e. (#16439)

If waitForAnyAdvertisement failed, we would not actually clean things up and sit there until the job timed out.  Two changes to fix that:

1) Add the app to the app register before calling start() on it, so
   that the killAll() on the app register has a chance of killing the
   app.

2) Set self.process immediately, instead of doing it after things that
   might fail (like waitForAnyAdvertisement), so killing the app actually
   works.
  • Loading branch information
bzbarsky-apple authored Mar 18, 2022
1 parent cfd5bf0 commit bbc944c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ def __init__(self, runner, command):

def start(self, discriminator):
if not self.process:
self.process = None
process, outpipe, errpipe = self.__startServer(
# Make sure to assign self.process before we do any operations that
# might fail, so attempts to kill us on failure actually work.
self.process, self.outpipe, errpipe = self.__startServer(
self.runner, self.command, discriminator)
self.waitForAnyAdvertisement(process, outpipe)
self.__updateSetUpCode(outpipe)
self.process = process
self.outpipe = outpipe
self.waitForAnyAdvertisement()
self.__updateSetUpCode()
with self.cv_stopped:
self.stopped = False
self.cv_stopped.notify()
Expand Down Expand Up @@ -78,8 +77,8 @@ def factoryReset(self):

return True

def waitForAnyAdvertisement(self, process, outpipe):
self.__waitFor("mDNS service published:", process, outpipe)
def waitForAnyAdvertisement(self):
self.__waitFor("mDNS service published:", self.process, self.outpipe)

def waitForCommissionableAdvertisement(self):
self.__waitFor("mDNS service published: _matterc._udp",
Expand Down Expand Up @@ -135,8 +134,8 @@ def __waitFor(self, waitForString, server_process, outpipe):

logging.debug('Success waiting for: %s' % waitForString)

def __updateSetUpCode(self, outpipe):
qrLine = outpipe.FindLastMatchingLine('.*SetupQRCode: *\\[(.*)]')
def __updateSetUpCode(self):
qrLine = self.outpipe.FindLastMatchingLine('.*SetupQRCode: *\\[(.*)]')
if not qrLine:
raise Exception("Unable to find QR code")
self.setupCode = qrLine.group(1)
Expand Down Expand Up @@ -232,11 +231,13 @@ def Run(self, runner, apps_register, paths: ApplicationPaths):
os.unlink(f)

app = App(runner, app_cmd)
# Add the App to the register immediately, so if it fails during
# start() we will be able to clean things up properly.
apps_register.add("default", app)
# Remove server application storage (factory reset),
# so it will be commissionable again.
app.factoryReset()
app.start(str(randrange(1, 4096)))
apps_register.add("default", app)

runner.RunSubprocess(
tool_cmd + ['pairing', 'qrcode', TEST_NODE_ID, app.setupCode],
Expand Down

0 comments on commit bbc944c

Please sign in to comment.