/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: John Arbash Meinel
  • Date: 2006-08-18 16:09:14 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1947.
  • Revision ID: john@arbash-meinel.com-20060818160914-b74c5ae654642c1e
Clean up PEP8 and unused imports in bench_sftp.py, and missing import in bzrlib/tests/test_sftp_transport.py

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
 
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 test_pull_1(self):
 
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, 1, 20)
 
54
        self.time(b2.open_branch().pull, rbzrdir.open_branch())
 
55
        
 
56
    def test_pull_100(self):
 
57
        os.mkdir("a")
 
58
        tree, files = self.create_with_commits(100, 100, "a")
 
59
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
 
60
        b2 = tree.bzrdir.sprout("b") # branch
 
61
        # change a few files and commit
 
62
        self.commit_some_revisions(tree, files, 100, 20)
 
63
        self.time(b2.open_branch().pull, rbzrdir.open_branch())
 
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 = rbzrdir.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_push_1(self):
 
79
        self.create_commit_and_push(1)
 
80
 
 
81
    def test_push_10(self):
 
82
        self.create_commit_and_push(10)
 
83
 
 
84
    def test_push_100(self):
 
85
        self.create_commit_and_push(100)
 
86
 
 
87
 
 
88
class SFTPSlowSocketBenchmark(SFTPBenchmark):
 
89
    def setUp(self):
 
90
        super(SFTPSlowSocketBenchmark, self).setUp()
 
91
        self.get_server().add_latency = 0.03
 
92