1
# Copyright (C) 2006 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for bzr performance over SFTP"""
24
from bzrlib.benchmarks import Benchmark
25
from bzrlib.tests import test_sftp_transport, TestSkipped
29
paramiko_loaded = True
31
paramiko_loaded = False
34
class SFTPBenchmark(Benchmark):
35
"""Benchmark branch, push and pull across a local sftp connection."""
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)
43
def test_branch(self):
45
tree, files = self.create_with_commits(100, 100, "a")
46
self.time(bzrdir.BzrDir.open(self.get_url('a')).sprout, "b")
48
def create_commit_and_pull(self, num_pull_revisions):
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())
57
def test_pull_1(self):
58
self.create_commit_and_pull(1)
60
def test_pull_10(self):
61
self.create_commit_and_pull(10)
63
def test_pull_100(self):
64
self.create_commit_and_pull(100)
66
def create_commit_and_push(self, num_push_revisions):
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)
79
def test_initial_push(self):
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())
85
def test_push_1(self):
86
self.create_commit_and_push(1)
88
def test_push_10(self):
89
self.create_commit_and_push(10)
91
def test_push_100(self):
92
self.create_commit_and_push(100)
95
class SFTPSlowSocketBenchmark(SFTPBenchmark):
96
"""Benchmarks of SFTP performance with a 30ms delay per roundtrip."""
99
super(SFTPSlowSocketBenchmark, self).setUp()
100
self.get_server().add_latency = 0.03