~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_pack_repository.py

  • Committer: John Arbash Meinel
  • Date: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
545
545
        finally:
546
546
            tree.unlock()
547
547
 
 
548
    def test_concurrent_pack_during_autopack(self):
 
549
        tree = self.make_branch_and_tree('tree')
 
550
        tree.lock_write()
 
551
        try:
 
552
            for i in xrange(9):
 
553
                tree.commit('rev %d' % (i,))
 
554
            r2 = repository.Repository.open('tree')
 
555
            r2.lock_write()
 
556
            try:
 
557
                # Monkey patch so that pack occurs while the other repo is
 
558
                # autopacking. This is slightly bad, but all current pack
 
559
                # repository implementations have a _pack_collection, and we
 
560
                # test that it gets triggered. So if a future format changes
 
561
                # things, the test will fail rather than succeed accidentally.
 
562
                autopack_count = [0]
 
563
                r1 = tree.branch.repository
 
564
                orig = r1._pack_collection.pack_distribution
 
565
                def trigger_during_auto(*args, **kwargs):
 
566
                    ret = orig(*args, **kwargs)
 
567
                    if not autopack_count[0]:
 
568
                        r2.pack()
 
569
                    autopack_count[0] += 1
 
570
                    return ret
 
571
                r1._pack_collection.pack_distribution = trigger_during_auto
 
572
                tree.commit('autopack-rev')
 
573
                # This triggers 2 autopacks. The first one causes r2.pack() to
 
574
                # fire, but r2 doesn't see the new pack file yet. The
 
575
                # autopack restarts and sees there are 2 files and there
 
576
                # should be only 1 for 10 commits. So it goes ahead and
 
577
                # finishes autopacking.
 
578
                self.assertEqual([2], autopack_count)
 
579
            finally:
 
580
                r2.unlock()
 
581
        finally:
 
582
            tree.unlock()
 
583
 
548
584
    def test_lock_write_does_not_physically_lock(self):
549
585
        repo = self.make_repository('.', format=self.get_format())
550
586
        repo.lock_write()
687
723
        # abort_write_group will not raise an error
688
724
        self.assertEqual(None, repo.abort_write_group(suppress_errors=True))
689
725
        # But it does log an error
690
 
        log_file = self._get_log(keep_log_file=True)
691
 
        self.assertContainsRe(log_file, 'abort_write_group failed')
692
 
        self.assertContainsRe(log_file, r'INFO  bzr: ERROR \(ignored\):')
 
726
        log = self.get_log()
 
727
        self.assertContainsRe(log, 'abort_write_group failed')
 
728
        self.assertContainsRe(log, r'INFO  bzr: ERROR \(ignored\):')
693
729
        if token is not None:
694
730
            repo.leave_lock_in_place()
695
731