annotate tests/test_hooks.py @ 1457:019c3e194fba

tests: optimise creating repositories and loading dumps Previously, we'd use svnadmin for creating repositories and loading dumps. That tends to be a bit slow, as it forks a new process and loads the Subversion libraries into it. Instead, we extend our existing Subversion wrappers and load the dumps using the API. This is a noticable speedup. The only downside is that we rely on Subversion and Subvertpy to correctly close all file descriptors; an assumption which hasn't always held in the past. I ran some benchmarks on my relatively slow Mac with $TMPDIR on a ramdisk, and they showed a significant change: I compared ten runs of each with Subvertpy: min: -18.8% (299.1s -> 243.0s) median: -20.0% (307.1s -> 245.6s) ...and three runs of each with SWIG: min: -22.8% (368.7s -> 284.7s) median: -25.7% (384.4s -> 285.5s) (Since the timing measures wall clock time, the minimum time is likely to be the most accurate and useful measurement.)
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Tue, 07 Jun 2016 09:15:53 +0200
parents 4f1461428334
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
919
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
1 import sys
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
2 import test_util
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
3 import unittest
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
4
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
5 from mercurial import hg
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
6 from mercurial import commands
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
7
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
8 class TestHooks(test_util.TestBase):
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
9 def setUp(self):
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
10 super(TestHooks, self).setUp()
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
11
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
12 def _loadupdate(self, fixture_name, *args, **kwargs):
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
13 kwargs = kwargs.copy()
1067
20850abfb91a test_hooks: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1044
diff changeset
14 kwargs.update(noupdate=False)
919
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
15 repo, repo_path = self.load_and_fetch(fixture_name, *args, **kwargs)
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
16 return repo, repo_path
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
17
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
18 def test_updatemetahook(self):
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
19 repo, repo_path = self._loadupdate('single_rev.svndump')
1417
4f1461428334 test_hooks: cope with localrepo.parents() going away
Augie Fackler <raf@durin42.com>
parents: 1067
diff changeset
20 state = repo[None].parents()
919
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
21 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
22 commands.pull(self.repo.ui, self.repo)
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
23
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
24 # Clone to a new repository and add a hook
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
25 new_wc_path = "%s-2" % self.wc_path
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
26 commands.clone(self.repo.ui, self.wc_path, new_wc_path)
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
27 newrepo = hg.repository(test_util.testui(), new_wc_path)
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
28 newrepo.ui.setconfig('hooks', 'changegroup.meta',
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
29 'python:hgsubversion.hooks.updatemeta.hook')
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
30
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
31 # Commit a rev that should trigger svn meta update
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
32 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed Again'})
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
33 commands.pull(self.repo.ui, self.repo)
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
34
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
35 self.called = False
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
36 import hgsubversion.svncommands
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
37 oldupdatemeta = hgsubversion.svncommands.updatemeta
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
38 def _updatemeta(ui, repo, args=[]):
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
39 self.called = True
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
40 hgsubversion.svncommands.updatemeta = _updatemeta
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
41
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
42 # Pull and make sure our updatemeta function gets called
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
43 commands.pull(newrepo.ui, newrepo)
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
44 hgsubversion.svncommands.updatemeta = oldupdatemeta
92bd7b3678ea Add a changegroup hook to update svn metadata
Brad Hall <bhall@fb.com>
parents:
diff changeset
45 self.assertTrue(self.called)