~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

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