Rev 6020: (spiv) Speed up TestCaseWithMemoryTransport._check_safety_net by reading the in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Jul 11 02:46:38 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6020 [merge]
revision-id: pqm at pqm.ubuntu.com-20110711024635-f39c8kz23s347m1t
parent: pqm at pqm.ubuntu.com-20110711020719-grdhcun2kagpyrpk
parent: andrew.bennetts at canonical.com-20110711020618-gcjgoeb5azwjrnu6
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-07-11 02:46:35 +0000
message:
  (spiv) Speed up TestCaseWithMemoryTransport._check_safety_net by reading the
   dirstate file directly rather than using WorkingTree.open(). (Andrew
   Bennetts)
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2011-06-27 15:42:09 +0000
+++ b/bzrlib/tests/__init__.py	2011-07-11 01:24:24 +0000
@@ -2505,7 +2505,11 @@
         real branch.
         """
         root = TestCaseWithMemoryTransport.TEST_ROOT
-        bzrdir.BzrDir.create_standalone_workingtree(root)
+        wt = bzrdir.BzrDir.create_standalone_workingtree(root)
+        # Hack for speed: remember the raw bytes of the dirstate file so that
+        # we don't need to re-open the wt to check it hasn't changed.
+        TestCaseWithMemoryTransport._SAFETY_NET_PRISTINE_DIRSTATE = (
+            wt.control_transport.get_bytes('dirstate'))
 
     def _check_safety_net(self):
         """Check that the safety .bzr directory have not been touched.
@@ -2514,10 +2518,10 @@
         propagating. This method ensures than a test did not leaked.
         """
         root = TestCaseWithMemoryTransport.TEST_ROOT
-        self.permit_url(_mod_transport.get_transport(root).base)
-        wt = workingtree.WorkingTree.open(root)
-        last_rev = wt.last_revision()
-        if last_rev != 'null:':
+        t = _mod_transport.get_transport(root)
+        self.permit_url(t.base)
+        if (t.get_bytes('.bzr/checkout/dirstate') != 
+                TestCaseWithMemoryTransport._SAFETY_NET_PRISTINE_DIRSTATE):
             # The current test have modified the /bzr directory, we need to
             # recreate a new one or all the followng tests will fail.
             # If you need to inspect its content uncomment the following line

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-07-08 07:41:36 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-07-11 02:06:18 +0000
@@ -63,6 +63,12 @@
   due to the order that `build_snapshot` performs its actions.
   (Andrew Bennetts)
 
+* `TestCaseWithMemoryTransport` is faster now: `_check_safety_net` now
+  just compares the bytes in the dirstate file to its pristine state,
+  rather than opening the WorkingTree and calling ``last_revision()``.
+  This reduces the overall test suite time by about 10% on my laptop.
+  (Andrew Bennetts)
+
 
 bzr 2.4b5
 #########




More information about the bazaar-commits mailing list