~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_pack_repository.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
546
546
        finally:
547
547
            tree.unlock()
548
548
 
 
549
    def test_concurrent_pack_during_autopack(self):
 
550
        tree = self.make_branch_and_tree('tree')
 
551
        tree.lock_write()
 
552
        try:
 
553
            for i in xrange(9):
 
554
                tree.commit('rev %d' % (i,))
 
555
            r2 = repository.Repository.open('tree')
 
556
            r2.lock_write()
 
557
            try:
 
558
                # Monkey patch so that pack occurs while the other repo is
 
559
                # autopacking. This is slightly bad, but all current pack
 
560
                # repository implementations have a _pack_collection, and we
 
561
                # test that it gets triggered. So if a future format changes
 
562
                # things, the test will fail rather than succeed accidentally.
 
563
                autopack_count = [0]
 
564
                r1 = tree.branch.repository
 
565
                orig = r1._pack_collection.pack_distribution
 
566
                def trigger_during_auto(*args, **kwargs):
 
567
                    ret = orig(*args, **kwargs)
 
568
                    if not autopack_count[0]:
 
569
                        r2.pack()
 
570
                    autopack_count[0] += 1
 
571
                    return ret
 
572
                r1._pack_collection.pack_distribution = trigger_during_auto
 
573
                tree.commit('autopack-rev')
 
574
                # This triggers 2 autopacks. The first one causes r2.pack() to
 
575
                # fire, but r2 doesn't see the new pack file yet. The
 
576
                # autopack restarts and sees there are 2 files and there
 
577
                # should be only 1 for 10 commits. So it goes ahead and
 
578
                # finishes autopacking.
 
579
                self.assertEqual([2], autopack_count)
 
580
            finally:
 
581
                r2.unlock()
 
582
        finally:
 
583
            tree.unlock()
 
584
 
549
585
    def test_lock_write_does_not_physically_lock(self):
550
586
        repo = self.make_repository('.', format=self.get_format())
551
587
        repo.lock_write()