91
91
# from its own revision history
92
92
br_a2.append_revision('a-b-c')
93
93
self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2)
95
# TODO: jam 20051218 Branch should no longer allow append_revision for revisions
96
# which don't exist. So this test needs to be rewritten
97
# RBC 20060403 the way to do this is to uncommit the revision from the
98
# repository after the commit
94
100
#TODO: test that fetch correctly does reweaving when needed. RBC 20051008
95
101
# Note that this means - updating the weave when ghosts are filled in to
96
102
# add the right parents.
186
196
br_rem_a = Branch.open(self.get_readonly_url('branch1'))
187
197
fetch_steps(self, br_rem_a, br_b, br_a)
199
def _count_log_matches(self, target, logs):
200
"""Count the number of times the target file pattern was fetched in an http log"""
201
log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
202
(target, bzrlib.__version__)
205
# TODO: perhaps use a regexp instead so we can match more
207
if line.find(log_pattern) > -1:
189
211
def test_weaves_are_retrieved_once(self):
190
212
self.build_tree(("source/", "source/file", "target/"))
191
213
wt = self.make_branch_and_tree('source')
197
219
target = BzrDir.create_branch_and_repo("target/")
198
220
source = Branch.open(self.get_readonly_url("source/"))
199
221
self.assertEqual(target.fetch(source), (2, []))
200
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s"' % bzrlib.__version__
222
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
201
223
# this is the path to the literal file. As format changes
202
224
# 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)]))
226
self.log("web server logs are:")
227
http_logs = self.get_readonly_server().logs
228
self.log('\n'.join(http_logs))
229
# unfortunately this log entry is branch format specific. We could
230
# factor out the 'what files does this format use' to a method on the
231
# repository, which would let us to this generically. RBC 20060419
232
self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
233
self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
234
self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
235
self.assertEqual(1, self._count_log_matches('inventory.knit', http_logs))
211
236
# this r-h check test will prevent regressions, but it currently already
212
237
# 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)]))
238
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
217
239
# FIXME naughty poking in there.
218
240
self.get_readonly_server().logs = []
219
241
# check there is nothing more to fetch
220
242
source = Branch.open(self.get_readonly_url("source/"))
221
243
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))
244
# should make just two requests
245
http_logs = self.get_readonly_server().logs
246
self.log("web server logs are:")
247
self.log('\n'.join(http_logs))
248
self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
249
self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
250
self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
251
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
252
self.assertEqual(4, len(http_logs))