Merge lp:~spiv/bzr/test-isolation-speed into lp:bzr

Proposed by Andrew Bennetts
Status: Merged
Approved by: Martin Pool
Approved revision: 6018
Merged at revision: 6020
Proposed branch: lp:~spiv/bzr/test-isolation-speed
Merge into: lp:bzr
Diff against target: 48 lines (+15/-5)
2 files modified
bzrlib/tests/__init__.py (+9/-5)
doc/en/release-notes/bzr-2.4.txt (+6/-0)
To merge this branch: bzr merge lp:~spiv/bzr/test-isolation-speed
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+67475@code.launchpad.net

Commit message

Speed up TestCaseWithMemoryTransport._check_safety_net by reading the dirstate file directly rather than using WorkingTree.open().

Description of the change

This hack reduces the total time for the test suite to run on my laptop by perhaps 10%. It replaces the WorkingTree.open(root).last_revision() == 'null:' check in _check_safety_net with just comparing the raw bytes of the dirstate file to their pristine state.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

cute

in theory we should see this show up in the babune graphs after it lands

Revision history for this message
Andrew Bennetts (spiv) wrote :

sent to pqm by email

lp:~spiv/bzr/test-isolation-speed updated
6019. By Andrew Bennetts

Merge lp:bzr/2.4.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/__init__.py'
2--- bzrlib/tests/__init__.py 2011-06-27 15:42:09 +0000
3+++ bzrlib/tests/__init__.py 2011-07-11 02:09:17 +0000
4@@ -2505,7 +2505,11 @@
5 real branch.
6 """
7 root = TestCaseWithMemoryTransport.TEST_ROOT
8- bzrdir.BzrDir.create_standalone_workingtree(root)
9+ wt = bzrdir.BzrDir.create_standalone_workingtree(root)
10+ # Hack for speed: remember the raw bytes of the dirstate file so that
11+ # we don't need to re-open the wt to check it hasn't changed.
12+ TestCaseWithMemoryTransport._SAFETY_NET_PRISTINE_DIRSTATE = (
13+ wt.control_transport.get_bytes('dirstate'))
14
15 def _check_safety_net(self):
16 """Check that the safety .bzr directory have not been touched.
17@@ -2514,10 +2518,10 @@
18 propagating. This method ensures than a test did not leaked.
19 """
20 root = TestCaseWithMemoryTransport.TEST_ROOT
21- self.permit_url(_mod_transport.get_transport(root).base)
22- wt = workingtree.WorkingTree.open(root)
23- last_rev = wt.last_revision()
24- if last_rev != 'null:':
25+ t = _mod_transport.get_transport(root)
26+ self.permit_url(t.base)
27+ if (t.get_bytes('.bzr/checkout/dirstate') !=
28+ TestCaseWithMemoryTransport._SAFETY_NET_PRISTINE_DIRSTATE):
29 # The current test have modified the /bzr directory, we need to
30 # recreate a new one or all the followng tests will fail.
31 # If you need to inspect its content uncomment the following line
32
33=== modified file 'doc/en/release-notes/bzr-2.4.txt'
34--- doc/en/release-notes/bzr-2.4.txt 2011-07-08 07:41:36 +0000
35+++ doc/en/release-notes/bzr-2.4.txt 2011-07-11 02:09:17 +0000
36@@ -63,6 +63,12 @@
37 due to the order that `build_snapshot` performs its actions.
38 (Andrew Bennetts)
39
40+* `TestCaseWithMemoryTransport` is faster now: `_check_safety_net` now
41+ just compares the bytes in the dirstate file to its pristine state,
42+ rather than opening the WorkingTree and calling ``last_revision()``.
43+ This reduces the overall test suite time by about 10% on my laptop.
44+ (Andrew Bennetts)
45+
46
47 bzr 2.4b5
48 #########