[MERGE] More than double the speed of "bzr selftest"

Andrew Bennetts andrew at canonical.com
Wed Apr 11 06:18:23 BST 2007


Now that I've got your attention ;)

Actually, this bundle really does more than double the speed of "bzr selftest"
on the full suite for me.  It takes the full time (as reported by "time", i.e.
including "cleaning up") down to 7m38s on my linux laptop with an ext3
filesystem, from 17m51s (this is on the hpss branch, which has over 6300 tests).
I'd expect similar gains in most environments, though.

The trick is simply to remove temporary directories after each (successful) test
method — they aren't needed, and by removing them immediately they never
actually hit the disk; they don't live long enough to get flushed out of the
kernel's buffers.  So the kernel's disk cache doesn't get filled with hundreds
of MB of temporary garbage, and there aren't hundreds of MB of temporary
directories and files to remove all at once at the end of the run.  Basically,
this simple change makes everything faster.

It did it as a quick hack, so comments welcome.

-Andrew.

-------------- next part --------------
# Bazaar revision bundle v0.9
#
# message:
#   Remove temporary directories from successful tests as soon as possible, thus making the full test suite much much faster.
# committer: Andrew Bennetts <andrew.bennetts at canonical.com>
# date: Wed 2007-04-11 15:17:06.888999939 +1000

=== modified file bzrlib/tests/__init__.py
--- bzrlib/tests/__init__.py
+++ bzrlib/tests/__init__.py
@@ -36,6 +36,7 @@
 from pprint import pformat
 import re
 import shlex
+import shutil
 import stat
 from subprocess import Popen, PIPE
 import sys
@@ -1833,6 +1834,18 @@
             self.log("actually: %r" % contents)
             self.fail("contents of %s not as expected" % filename)
 
+    def run(self, result=None):
+        try:
+            return TestCaseWithMemoryTransport.run(self, result=result)
+        finally:
+            # If the test passed, we can delete its temporary files.
+            if result is not None and result.wasSuccessful():
+                # If the test raised TestSkipped during setUp, test_dir might
+                # not be set.
+                if getattr(self, 'test_dir', None) is not None:
+                    assert self.test_dir.endswith('/work'), self.test_dir
+                    shutil.rmtree(self.test_dir[:-len('/work')])
+
     def makeAndChdirToTestDir(self):
         """See TestCaseWithMemoryTransport.makeAndChdirToTestDir().
         

=== modified directory  // last-changed:andrew.bennetts at canonical.com-200704110
... 51706-i5k643i402dtvzu3
# revision id: andrew.bennetts at canonical.com-20070411051706-i5k643i402dtvzu3
# sha1: e7a53af7aba39c00862796ad5eb7abd84d8329ce
# inventory sha1: 08e5fd977e47fd7d2330dea25a238a88a7ea8460
# parent ids:
#   pqm at pqm.ubuntu.com-20070411022359-403a2155afb207cf
# base id: pqm at pqm.ubuntu.com-20070411022359-403a2155afb207cf
# properties:
#   branch-nick: faster-tests



More information about the bazaar mailing list