/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_sftp.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License version 2 as published by
 
5
# the Free Software Foundation.
 
6
#
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program; if not, write to the Free Software
 
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
 
 
16
"""Tests for bzr performance over SFTP"""
 
17
 
 
18
import os
 
19
 
 
20
from bzrlib import (
 
21
    bzrdir,
 
22
    )
 
23
from bzrlib.benchmarks import Benchmark
 
24
from bzrlib.tests import test_sftp_transport, TestSkipped
 
25
 
 
26
try:
 
27
    import paramiko
 
28
    paramiko_loaded = True
 
29
except ImportError:
 
30
    paramiko_loaded = False
 
31
 
 
32
 
 
33
class SFTPBenchmark(Benchmark):
 
34
    """Benchmark branch, push and pull across a local sftp connection."""
 
35
 
 
36
    def setUp(self):
 
37
        super(SFTPBenchmark, self).setUp()
 
38
        if not paramiko_loaded:
 
39
            raise TestSkipped('you must have paramiko to run this test')
 
40
        test_sftp_transport.set_test_transport_to_sftp(self)
 
41
         
 
42
    def test_branch(self):
 
43
        os.mkdir("a")
 
44
        tree, files = self.create_with_commits(100, 100, "a")
 
45
        self.time(bzrdir.BzrDir.open(self.get_url('a')).sprout, "b")
 
46
 
 
47
    def create_commit_and_pull(self, num_pull_revisions):
 
48
        os.mkdir("a")
 
49
        tree, files = self.create_with_commits(100, 100, "a")
 
50
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
 
51
        b2 = tree.bzrdir.sprout("b") # branch
 
52
        # change a few files and commit
 
53
        self.commit_some_revisions(tree, files, num_pull_revisions, 20)
 
54
        self.time(b2.open_branch().pull, rbzrdir.open_branch())
 
55
 
 
56
    def test_pull_1(self):
 
57
        self.create_commit_and_pull(1)
 
58
        
 
59
    def test_pull_10(self):
 
60
        self.create_commit_and_pull(10)
 
61
 
 
62
    def test_pull_100(self):
 
63
        self.create_commit_and_pull(100)
 
64
 
 
65
    def create_commit_and_push(self, num_push_revisions):
 
66
        os.mkdir("a")
 
67
        tree, files = self.create_with_commits(100, 100, "a")
 
68
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
 
69
        b2 = tree.bzrdir.sprout("b") # branch
 
70
        wtree = b2.open_workingtree()
 
71
        # change a few files and commit
 
72
        self.commit_some_revisions(
 
73
            wtree, ["b/%i" for i in range(100)],
 
74
            num_commits=num_push_revisions,
 
75
            changes_per_commit=20)
 
76
        self.time(rbzrdir.open_branch().pull, wtree.branch)
 
77
 
 
78
    def test_initial_push(self):
 
79
        os.mkdir('a')
 
80
        tree, files = self.create_with_commits(100, 100, "a")
 
81
        self.time(tree.bzrdir.clone, self.get_url('b'),
 
82
                  revision_id=tree.last_revision())
 
83
 
 
84
    def test_push_1(self):
 
85
        self.create_commit_and_push(1)
 
86
 
 
87
    def test_push_10(self):
 
88
        self.create_commit_and_push(10)
 
89
 
 
90
    def test_push_100(self):
 
91
        self.create_commit_and_push(100)
 
92
 
 
93
 
 
94
class SFTPSlowSocketBenchmark(SFTPBenchmark):
 
95
    def setUp(self):
 
96
        super(SFTPSlowSocketBenchmark, self).setUp()
 
97
        self.get_server().add_latency = 0.03
 
98