103
103
br_a, br_b = make_branches(self)
104
104
fetch_steps(self, br_a, br_b, br_a)
106
def test_fetch_self(self):
107
wt = self.make_branch_and_tree('br')
108
self.assertEqual(wt.branch.fetch(wt.branch), (0, []))
107
111
class TestMergeFetch(TestCaseWithTransport):
186
190
br_rem_a = Branch.open(self.get_readonly_url('branch1'))
187
191
fetch_steps(self, br_rem_a, br_b, br_a)
193
def _count_log_matches(self, target, logs):
194
"""Count the number of times the target file pattern was fetched in an http log"""
195
log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
196
(target, bzrlib.__version__)
199
# TODO: perhaps use a regexp instead so we can match more
201
if line.find(log_pattern) > -1:
189
205
def test_weaves_are_retrieved_once(self):
190
206
self.build_tree(("source/", "source/file", "target/"))
191
207
wt = self.make_branch_and_tree('source')
197
213
target = BzrDir.create_branch_and_repo("target/")
198
214
source = Branch.open(self.get_readonly_url("source/"))
199
215
self.assertEqual(target.fetch(source), (2, []))
200
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s"' % bzrlib.__version__
216
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
201
217
# this is the path to the literal file. As format changes
202
218
# occur it needs to be updated. FIXME: ask the store for the
204
weave_suffix = log_pattern % 'weaves/ce/id.weave'
206
len([log for log in self.get_readonly_server().logs if log.endswith(weave_suffix)]))
207
inventory_weave_suffix = log_pattern % 'inventory.weave'
209
len([log for log in self.get_readonly_server().logs if log.endswith(
210
inventory_weave_suffix)]))
220
self.log("web server logs are:")
221
http_logs = self.get_readonly_server().logs
222
self.log('\n'.join(http_logs))
223
self.assertEqual(1, self._count_log_matches('weaves/ce/id.weave', http_logs))
224
self.assertEqual(1, self._count_log_matches('inventory.weave', http_logs))
211
225
# this r-h check test will prevent regressions, but it currently already
212
226
# passes, before the patch to cache-rh is applied :[
213
revision_history_suffix = log_pattern % 'revision-history'
215
len([log for log in self.get_readonly_server().logs if log.endswith(
216
revision_history_suffix)]))
227
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
217
228
# FIXME naughty poking in there.
218
229
self.get_readonly_server().logs = []
219
230
# check there is nothing more to fetch
220
231
source = Branch.open(self.get_readonly_url("source/"))
221
232
self.assertEqual(target.fetch(source), (0, []))
222
self.failUnless(self.get_readonly_server().logs[0].endswith(log_pattern % 'branch-format'))
223
self.failUnless(self.get_readonly_server().logs[1].endswith(log_pattern % 'revision-history'))
224
self.assertEqual(2, len(self.get_readonly_server().logs))
233
# should make just two requests
234
http_logs = self.get_readonly_server().logs
235
self.log("web server logs are:")
236
self.log('\n'.join(http_logs))
237
self.assertEqual(1, self._count_log_matches('branch-format', http_logs[0:1]))
238
self.assertEqual(1, self._count_log_matches('revision-history', http_logs[1:2]))
239
self.assertEqual(2, len(http_logs))