Mercurial > hg
comparison tests/run-tests.py @ 43594:ac140b85aae9
tests: use time.time() for relative start and stop times
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
acceptable.
Differential Revision: https://phab.mercurial-scm.org/D7126
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 16 Oct 2019 21:31:40 -0700 |
parents | ae91e4e4c9b0 |
children | 3fe91bcd5199 |
comparison
equal
deleted
inserted
replaced
43593:ae91e4e4c9b0 | 43594:ac140b85aae9 |
---|---|
2244 super(TestResult, self).startTest(test) | 2244 super(TestResult, self).startTest(test) |
2245 | 2245 |
2246 # os.times module computes the user time and system time spent by | 2246 # os.times module computes the user time and system time spent by |
2247 # child's processes along with real elapsed time taken by a process. | 2247 # child's processes along with real elapsed time taken by a process. |
2248 # This module has one limitation. It can only work for Linux user | 2248 # This module has one limitation. It can only work for Linux user |
2249 # and not for Windows. | 2249 # and not for Windows. Hence why we fall back to another function |
2250 # for wall time calculations. | |
2250 test.started_times = os.times() | 2251 test.started_times = os.times() |
2252 # TODO use a monotonic clock once support for Python 2.7 is dropped. | |
2253 test.started_time = time.time() | |
2251 if self._firststarttime is None: # thread racy but irrelevant | 2254 if self._firststarttime is None: # thread racy but irrelevant |
2252 self._firststarttime = test.started_times[4] | 2255 self._firststarttime = test.started_time |
2253 | 2256 |
2254 def stopTest(self, test, interrupted=False): | 2257 def stopTest(self, test, interrupted=False): |
2255 super(TestResult, self).stopTest(test) | 2258 super(TestResult, self).stopTest(test) |
2256 | 2259 |
2257 test.stopped_times = os.times() | 2260 test.stopped_times = os.times() |
2261 stopped_time = time.time() | |
2258 | 2262 |
2259 starttime = test.started_times | 2263 starttime = test.started_times |
2260 endtime = test.stopped_times | 2264 endtime = test.stopped_times |
2261 origin = self._firststarttime | 2265 origin = self._firststarttime |
2262 self.times.append( | 2266 self.times.append( |
2263 ( | 2267 ( |
2264 test.name, | 2268 test.name, |
2265 endtime[2] - starttime[2], # user space CPU time | 2269 endtime[2] - starttime[2], # user space CPU time |
2266 endtime[3] - starttime[3], # sys space CPU time | 2270 endtime[3] - starttime[3], # sys space CPU time |
2267 endtime[4] - starttime[4], # real time | 2271 stopped_time - test.started_time, # real time |
2268 starttime[4] - origin, # start date in run context | 2272 test.started_time - origin, # start date in run context |
2269 endtime[4] - origin, # end date in run context | 2273 stopped_time - origin, # end date in run context |
2270 ) | 2274 ) |
2271 ) | 2275 ) |
2272 | 2276 |
2273 if interrupted: | 2277 if interrupted: |
2274 with iolock: | 2278 with iolock: |