~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-24 20:31:26 UTC
  • mto: (3860.1.1 153786-retry)
  • mto: This revision was merged to the branch mainline in revision 3865.
  • Revision ID: john@arbash-meinel.com-20081024203126-koei1a77u0qa4abq
Change the mocking a bit, so we can be sure it is failing at the right time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
273
273
class MockReadvFailingTransport(MockTransport):
274
274
    """Fail in the middle of a readv() result.
275
275
 
276
 
    This Transport will successfully yield the first requested hunk, but raise
277
 
    NoSuchFile for the rest.
 
276
    This Transport will successfully yield the first two requested hunks, but
 
277
    raise NoSuchFile for the rest.
278
278
    """
279
279
 
280
280
    def readv(self, relpath, offsets):
281
 
        first = True
 
281
        count = 0
282
282
        for result in MockTransport.readv(self, relpath, offsets):
283
 
            if not first:
 
283
            count += 1
 
284
            # we use 2 because the first offset is the pack header, the second
 
285
            # is the first actual content requset
 
286
            if count > 2:
284
287
                raise errors.NoSuchFile(relpath)
285
 
            first = False
286
288
            yield result
287
289
 
288
290
 
422
424
        transport = self.get_transport()
423
425
        failing_transport = MockReadvFailingTransport(
424
426
                                [transport.get_bytes('packname')])
425
 
        # The readv() will fail mid-way through
426
427
        access = _DirectPackAccess({'foo':(failing_transport, 'packname')})
 
428
        # Asking for a single record will not trigger the Mock failure
 
429
        self.assertEqual(['1234567890'],
 
430
            list(access.get_raw_records(memos[:1])))
 
431
        self.assertEqual(['12345'],
 
432
            list(access.get_raw_records(memos[1:2])))
 
433
        # A multiple offset readv() will fail mid-way through
427
434
        e = self.assertListRaises(errors.RetryWithNewPacks,
428
435
                                  access.get_raw_records, memos)
429
436
        # The file has gone missing, so we assume we need to reload