~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_sftp.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-12 21:18:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2415.
  • Revision ID: john@arbash-meinel.com-20070412211829-dduwktk8in0e6zpl
Clean up test ordering

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 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 as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
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
 
 
19
import os
 
20
 
 
21
from bzrlib import (
 
22
    bzrdir,
 
23
    )
 
24
from bzrlib.benchmarks import Benchmark
 
25
from bzrlib.tests import test_sftp_transport, TestSkipped
 
26
 
 
27
try:
 
28
    import paramiko
 
29
    paramiko_loaded = True
 
30
except ImportError:
 
31
    paramiko_loaded = False
 
32
 
 
33
 
 
34
class SFTPBenchmark(Benchmark):
 
35
    """Benchmark branch, push and pull across a local sftp connection."""
 
36
 
 
37
    def setUp(self):
 
38
        super(SFTPBenchmark, self).setUp()
 
39
        if not paramiko_loaded:
 
40
            raise TestSkipped('you must have paramiko to run this test')
 
41
        test_sftp_transport.set_test_transport_to_sftp(self)
 
42
         
 
43
    def test_branch(self):
 
44
        os.mkdir("a")
 
45
        tree, files = self.create_with_commits(100, 100, "a")
 
46
        self.time(bzrdir.BzrDir.open(self.get_url('a')).sprout, "b")
 
47
 
 
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
 
 
57
    def test_pull_1(self):
 
58
        self.create_commit_and_pull(1)
 
59
        
 
60
    def test_pull_10(self):
 
61
        self.create_commit_and_pull(10)
 
62
 
 
63
    def test_pull_100(self):
 
64
        self.create_commit_and_pull(100)
 
65
 
 
66
    def create_commit_and_push(self, num_push_revisions):
 
67
        os.mkdir("a")
 
68
        tree, files = self.create_with_commits(100, 100, "a")
 
69
        rbzrdir = bzrdir.BzrDir.open(self.get_url('a'))
 
70
        b2 = tree.bzrdir.sprout("b") # branch
 
71
        wtree = b2.open_workingtree()
 
72
        # change a few files and commit
 
73
        self.commit_some_revisions(
 
74
            wtree, ["b/%i" for i in range(100)],
 
75
            num_commits=num_push_revisions,
 
76
            changes_per_commit=20)
 
77
        self.time(rbzrdir.open_branch().pull, wtree.branch)
 
78
 
 
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
 
 
85
    def test_push_1(self):
 
86
        self.create_commit_and_push(1)
 
87
 
 
88
    def test_push_10(self):
 
89
        self.create_commit_and_push(10)
 
90
 
 
91
    def test_push_100(self):
 
92
        self.create_commit_and_push(100)
 
93
 
 
94
 
 
95
class SFTPSlowSocketBenchmark(SFTPBenchmark):
 
96
    def setUp(self):
 
97
        super(SFTPSlowSocketBenchmark, self).setUp()
 
98
        self.get_server().add_latency = 0.03
 
99