Skip to content

Commit

Permalink
Use monotonic clock for measuring intervals in tests. (#19659)
Browse files Browse the repository at this point in the history
This way we won't get spurious timeouts from clock changes.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 2, 2022
1 parent 53ae1f0 commit 1294891
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __startServer(self, runner, command):
def __waitFor(self, waitForString, server_process, outpipe):
logging.debug('Waiting for %s' % waitForString)

start_time = time.time()
start_time = time.monotonic()
ready, self.lastLogIndex = outpipe.CapturedLogContains(
waitForString, self.lastLogIndex)
while not ready:
Expand All @@ -128,7 +128,7 @@ def __waitFor(self, waitForString, server_process, outpipe):
(waitForString, server_process.returncode))
logging.error(died_str)
raise Exception(died_str)
if time.time() - start_time > 10:
if time.monotonic() - start_time > 10:
raise Exception('Timeout while waiting for %s' % waitForString)
time.sleep(0.1)
ready, self.lastLogIndex = outpipe.CapturedLogContains(
Expand Down
6 changes: 3 additions & 3 deletions scripts/tests/run_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ def cmd_run(context, iterations, all_clusters_app, lock_app, ota_provider_app, o
for i in range(iterations):
logging.info("Starting iteration %d" % (i+1))
for test in context.obj.tests:
test_start = time.time()
test_start = time.monotonic()
try:
test.Run(runner, apps_register, paths, pics_file)
test_end = time.time()
test_end = time.monotonic()
logging.info('%-20s - Completed in %0.2f seconds' %
(test.name, (test_end - test_start)))
except Exception:
test_end = time.time()
test_end = time.monotonic()
logging.exception('%s - FAILED in %0.2f seconds' %
(test.name, (test_end - test_start)))
apps_register.uninit()
Expand Down

0 comments on commit 1294891

Please sign in to comment.