Bug 1215834: Replace the hand-made total_seconds function by the standard one; r=sfink
authorBenjamin Bouvier <benj@benj.me>
Mon, 21 Mar 2016 14:19:10 +0100
changeset 338595 5389ec93bfd0ff693cefc99d05bf603e3dabbc13
parent 338594 6862e8f620275fd29c8cae07efdd7503baed9581
child 338596 1989e902ec648e2eb6dc5d28bb32d5d1b00904d5
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1215834
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1215834: Replace the hand-made total_seconds function by the standard one; r=sfink Also use timedelta's method total_seconds() instead of an external total_seconds() function. MozReview-Commit-ID: IUpP9BPFAg1
js/src/tests/lib/tasks_unix.py
--- a/js/src/tests/lib/tasks_unix.py
+++ b/js/src/tests/lib/tasks_unix.py
@@ -43,23 +43,16 @@ def spawn_test(test, prefix, passthrough
         os.close(rout)
         os.close(rerr)
 
         os.dup2(wout, 1)
         os.dup2(werr, 2)
 
     os.execvp(cmd[0], cmd)
 
-def total_seconds(td):
-    """
-    Return the total number of seconds contained in the duration as a float
-    """
-    return (float(td.microseconds) \
-            + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
-
 def get_max_wait(tasks, timeout):
     """
     Return the maximum time we can wait before any task should time out.
     """
 
     # If we have a progress-meter, we need to wake up to update it frequently.
     wait = ProgressBar.update_granularity()
 
@@ -68,28 +61,18 @@ def get_max_wait(tasks, timeout):
     if timeout:
         now = datetime.now()
         timeout_delta = timedelta(seconds=timeout)
         for task in tasks:
             remaining = task.start + timeout_delta - now
             if remaining < wait:
                 wait = remaining
 
-    if wait > ProgressBar.update_granularity():
-        print >> sys.stderr, "Inconsistent return value in get_max_wait:"
-        for task in tasks:
-            print >> sys.stderr, "\tstart={} elapsed={} remaining={}".format(\
-                    task.start, total_seconds(now - task.start), \
-                    total_seconds(task.start + timeout_delta - now))
-        print >> sys.stderr, "wait={} total_seconds(wait)={} timeout={} \
-        update_granularity={} now={}".format(wait, total_seconds(wait), \
-                timeout, total_seconds(ProgressBar.update_granularity()), now)
-
-    # Return the wait time in seconds, clamped to zero.
-    return max(total_seconds(wait), 0)
+    # Return the wait time in seconds, clamped between zero and max_wait.
+    return max(wait.total_seconds(), 0)
 
 def flush_input(fd, frags):
     """
     Read any pages sitting in the file descriptor 'fd' into the list 'frags'.
     """
     rv = os.read(fd, 4096)
     frags.append(rv)
     while len(rv) == 4096:
@@ -187,17 +170,17 @@ def reap_zombies(tasks, timeout):
 
         finished.append(
             TestOutput(
                 ended.test,
                 ended.cmd,
                 ''.join(ended.out),
                 ''.join(ended.err),
                 returncode,
-                total_seconds(datetime.now() - ended.start),
+                (datetime.now() - ended.start).total_seconds(),
                 timed_out(ended, timeout)))
     return tasks, finished
 
 def kill_undead(tasks, timeout):
     """
     Signal all children that are over the given timeout.
     """
     for task in tasks: