~bzr-pqm/bzr/bzr.dev

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
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
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
18
import os
1874.1.14 by Carl Friedrich Bolz
Rename setup method to make its intent clearer. Some PEP 8 issues.
19
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
20
from bzrlib import (
21
    bzrdir,
22
    )
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
23
from bzrlib.benchmarks import Benchmark
1874.1.14 by Carl Friedrich Bolz
Rename setup method to make its intent clearer. Some PEP 8 issues.
24
from bzrlib.tests import test_sftp_transport
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
25
26
try:
27
    import paramiko
28
    paramiko_loaded = True
29
except ImportError:
30
    paramiko_loaded = False
31
32
33
class SFTPBenchmark(Benchmark):
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
34
    """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
35
36
    def setUp(self):
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
37
        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
38
        if not paramiko_loaded:
39
            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
40
        test_sftp_transport.set_test_transport_to_sftp(self)
1874.1.6 by holger krekel
(cfbolz, hpk) Factor out common set_transport code.
41
         
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
42
    def test_branch(self):
43
        os.mkdir("a")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
44
        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
45
        self.time(bzrdir.BzrDir.open(self.get_url('a')).sprout, "b")
46
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
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
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
56
    def test_pull_1(self):
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
57
        self.create_commit_and_pull(1)
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
58
        
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
59
    def test_pull_10(self):
60
        self.create_commit_and_pull(10)
61
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
62
    def test_pull_100(self):
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
63
        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
64
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
65
    def create_commit_and_push(self, num_push_revisions):
66
        os.mkdir("a")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
67
        tree, files = self.create_with_commits(100, 100, "a")
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
68
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
1711.2.133 by John Arbash Meinel
Fix whitespace, and push sprout()ing over sftp
69
        b2 = tree.bzrdir.sprout("b") # branch
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
70
        wtree = b2.open_workingtree()
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
71
        # change a few files and commit
72
        self.commit_some_revisions(
1711.2.133 by John Arbash Meinel
Fix whitespace, and push sprout()ing over sftp
73
            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.
74
            num_commits=num_push_revisions,
75
            changes_per_commit=20)
1874.1.13 by Carl Friedrich Bolz
Typos.
76
        self.time(rbzrdir.open_branch().pull, wtree.branch)
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
77
1711.2.134 by John Arbash Meinel
Add a couple more sftp benchmarks
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
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
84
    def test_push_1(self):
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
85
        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
86
87
    def test_push_10(self):
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
88
        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
89
90
    def test_push_100(self):
1874.1.7 by holger krekel
(cfbolz, hpk) Factor out common code.
91
        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
92
93
94
class SFTPSlowSocketBenchmark(SFTPBenchmark):
95
    def setUp(self):
96
        super(SFTPSlowSocketBenchmark, self).setUp()
97
        self.get_server().add_latency = 0.03
98