Patchwork D7126: tests: use time.time() for relative start and stop times

login
register
mail settings
Submitter phabricator
Date Nov. 11, 2019, 12:35 p.m.
Message ID <c34687c77ddc65549539a4b8f576a68a@localhost.localdomain>
Download mbox | patch
Permalink /patch/43116/
State Not Applicable
Headers show

Comments

phabricator - Nov. 11, 2019, 12:35 p.m.
Closed by commit rHGac140b85aae9: tests: use time.time() for relative start and stop times (authored by indygreg).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7126?vs=17325&id=18013

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7126/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7126

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -2246,15 +2246,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[4]
+            self._firststarttime = test.started_time
 
     def stopTest(self, test, interrupted=False):
         super(TestResult, self).stopTest(test)
 
         test.stopped_times = os.times()
+        stopped_time = time.time()
 
         starttime = test.started_times
         endtime = test.stopped_times
@@ -2264,9 +2268,9 @@ 
                 test.name,
                 endtime[2] - starttime[2],  # user space CPU time
                 endtime[3] - starttime[3],  # sys  space CPU time
-                endtime[4] - starttime[4],  # real time
-                starttime[4] - origin,  # start date in run context
-                endtime[4] - 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
             )
         )