D7126: tests: use time.time() for relative start and stop times
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Thu Oct 17 19:31:02 EDT 2019
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
os.times() does not work on Windows. This was resulting in the
test start, stop, and duration times being reported as 0.
This commit swaps in time.time() for wall clock measurements.
This isn't ideal, as time.time() is not monotonic. But Python 2.7
does not have a monotonic timer that works on Windows. So it is
the best we have which is trivially usable. And test times aren't
terribly important, so variances due to clock skew are arguably
diff --git a/tests/run-tests.py b/tests/run-tests.py
@@ -2244,15 +2244,19 @@
# os.times module computes the user time and system time spent by
# child's processes along with real elapsed time taken by a process.
# This module has one limitation. It can only work for Linux user
- # and not for Windows.
+ # and not for Windows. Hence why we fall back to another function
+ # for wall time calculations.
test.started_times = os.times()
+ # TODO use a monotonic clock once support for Python 2.7 is dropped.
+ test.started_time = time.time()
if self._firststarttime is None: # thread racy but irrelevant
- self._firststarttime = test.started_times
+ self._firststarttime = test.started_time
def stopTest(self, test, interrupted=False):
test.stopped_times = os.times()
+ stopped_time = time.time()
starttime = test.started_times
endtime = test.stopped_times
@@ -2262,9 +2266,9 @@
endtime - starttime, # user space CPU time
endtime - starttime, # sys space CPU time
- endtime - starttime, # real time
- starttime - origin, # start date in run context
- endtime - origin, # end date in run context
+ stopped_time - test.started_time, # real time
+ test.started_time - origin, # start date in run context
+ stopped_time - origin, # end date in run context
To: indygreg, #hg-reviewers
More information about the Mercurial-devel