~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1711.2.132 by John Arbash Meinel
Clean up PEP8 and unused imports in bench_sftp.py, and missing import in bzrlib/tests/test_sftp_transport.py
2
#
3
# This program is free software; you can redistribute it and/or modify
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1711.2.132 by John Arbash Meinel
Clean up PEP8 and unused imports in bench_sftp.py, and missing import in bzrlib/tests/test_sftp_transport.py
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for bzr performance over SFTP"""
18
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
19
import os
1874.1.14 by Carl Friedrich Bolz
Rename setup method to make its intent clearer. Some PEP 8 issues.
20
1711.2.132 by John Arbash Meinel
Clean up PEP8 and unused imports in bench_sftp.py, and missing import in bzrlib/tests/test_sftp_transport.py
21
from bzrlib import (
22
    bzrdir,
23
    )
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
24
from bzrlib.benchmarks import Benchmark
2022.2.2 by Martin Pool
fix imports in bench_sftp
25
from bzrlib.tests import test_sftp_transport, TestSkipped
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
26
27
try:
28
    import paramiko
29
    paramiko_loaded = True
30
except ImportError:
31
    paramiko_loaded = False
32
33
34
class SFTPBenchmark(Benchmark):
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
35
    """Benchmark branch, push and pull across a local sftp connection."""
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
36
37
    def setUp(self):
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
38
        super(SFTPBenchmark, self).setUp()
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
39
        if not paramiko_loaded:
40
            raise TestSkipped('you must have paramiko to run this test')
1711.2.133 by John Arbash Meinel
Fix whitespace, and push sprout()ing over sftp
41
        test_sftp_transport.set_test_transport_to_sftp(self)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
42
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
43
    def test_branch(self):
44
        os.mkdir("a")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
45
        tree, files = self.create_with_commits(100, 100, "a")
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
46
        self.time(bzrdir.BzrDir.open(self.get_url('a')).sprout, "b")
47
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
48
    def create_commit_and_pull(self, num_pull_revisions):
49
        os.mkdir("a")
50
        tree, files = self.create_with_commits(100, 100, "a")
51
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
52
        b2 = tree.bzrdir.sprout("b") # branch
53
        # change a few files and commit
54
        self.commit_some_revisions(tree, files, num_pull_revisions, 20)
55
        self.time(b2.open_branch().pull, rbzrdir.open_branch())
56
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
57
    def test_pull_1(self):
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
58
        self.create_commit_and_pull(1)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
59
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
60
    def test_pull_10(self):
61
        self.create_commit_and_pull(10)
62
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
63
    def test_pull_100(self):
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
64
        self.create_commit_and_pull(100)
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
65
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
66
    def create_commit_and_push(self, num_push_revisions):
67
        os.mkdir("a")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
68
        tree, files = self.create_with_commits(100, 100, "a")
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
69
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
1711.2.133 by John Arbash Meinel
Fix whitespace, and push sprout()ing over sftp
70
        b2 = tree.bzrdir.sprout("b") # branch
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
71
        wtree = b2.open_workingtree()
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
72
        # change a few files and commit
73
        self.commit_some_revisions(
1711.2.133 by John Arbash Meinel
Fix whitespace, and push sprout()ing over sftp
74
            wtree, ["b/%i" for i in range(100)],
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
75
            num_commits=num_push_revisions,
76
            changes_per_commit=20)
1874.1.13 by Carl Friedrich Bolz
Typos.
77
        self.time(rbzrdir.open_branch().pull, wtree.branch)
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
78
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
79
    def test_initial_push(self):
80
        os.mkdir('a')
81
        tree, files = self.create_with_commits(100, 100, "a")
82
        self.time(tree.bzrdir.clone, self.get_url('b'),
83
                  revision_id=tree.last_revision())
84
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
85
    def test_push_1(self):
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
86
        self.create_commit_and_push(1)
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
87
88
    def test_push_10(self):
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
89
        self.create_commit_and_push(10)
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
90
91
    def test_push_100(self):
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
92
        self.create_commit_and_push(100)
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
93
94
95
class SFTPSlowSocketBenchmark(SFTPBenchmark):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
96
    """Benchmarks of SFTP performance with a 30ms delay per roundtrip."""
97
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
98
    def setUp(self):
99
        super(SFTPSlowSocketBenchmark, self).setUp()
100
        self.get_server().add_latency = 0.03
101