[Checkins] SVN: z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py Keep statistics on run-time of tests and re-arrange parallel test runs

Christian Theune ct at gocept.com
Thu Jan 29 07:17:12 EST 2009


Log message for revision 95422:
  Keep statistics on run-time of tests and re-arrange parallel test runs
  in a way that runs long-running tests first.
  

Changed:
  U   z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py

-=-
Modified: z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py
===================================================================
--- z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py	2009-01-29 12:16:25 UTC (rev 95421)
+++ z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py	2009-01-29 12:17:12 UTC (rev 95422)
@@ -3,6 +3,8 @@
 import select
 import subprocess
 import sys
+import time
+import pickle
 
 
 def usage():
@@ -23,6 +25,7 @@
         self.exitcode = None
 
     def start(self):
+        self.start = time.time()
         self.process = subprocess.Popen(
             [self.script, '--exit-with-status'] + self.args,
             stdin=subprocess.PIPE,
@@ -31,6 +34,8 @@
 
     def poll(self):
         self.exitcode = self.process.poll()
+        if self.exitcode is not None:
+            self.end = time.time()
         read, _, _ = select.select([self.process.stdout], [], [], 0.01)
         if read:
             self.output.write(read[0].read())
@@ -46,6 +51,23 @@
     completed = []
     scripts = list(scripts)
 
+    # Read statistics from the last run and re-order testing to start
+    # the slowest tests first.
+    stat_file_name = os.path.join(os.path.expanduser('~'), '.zope.teststats')
+    try:
+        stat_file = open(stat_file_name, 'r')
+    except IOError:
+        stats = {}
+    else:
+        stats = pickle.load(stat_file)
+        stat_file.close()
+    if stats:
+        default_time = sum(stats.values()) / float(len(stats))
+    else:
+        default_time = 0
+    scripts.sort(key=lambda package:-stats.get(os.path.basename(package), default_time))
+
+    # Main loop for controlling test runs
     while scripts or running:
         for job in running:
             job.poll()
@@ -64,7 +86,19 @@
             job.start()
             running.append(job)
 
+    # Result output
     failures = [job for job in completed if job.exitcode]
     print "%d failure(s)." % len(failures)
     for job in failures:
         print "-", job.name
+
+    # Store statistics
+    for job in completed:
+        stats[job.name] = job.end - job.start
+    try:
+        stat_file = open(stat_file_name, 'w')
+    except IOError:
+        # Statistics aren't that important. Just ignore that.
+        pass
+    else:
+        pickle.dump(stats, stat_file)



More information about the Checkins mailing list