~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockdir.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
16
16
 
17
17
"""Tests for LockDir"""
18
18
 
19
 
from cStringIO import StringIO
20
19
import os
21
20
from threading import Thread, Lock
22
21
import time
34
33
    LockBreakMismatch,
35
34
    LockBroken,
36
35
    LockContention,
37
 
    LockError,
38
36
    LockFailed,
39
37
    LockNotHeld,
40
38
    )
41
39
from bzrlib.lockdir import LockDir
42
40
from bzrlib.tests import (
 
41
    features,
43
42
    TestCaseWithTransport,
44
43
    )
45
44
from bzrlib.trace import note
582
581
                self.prompts.append(('boolean', prompt))
583
582
                return True
584
583
        ui = LoggingUIFactory()
585
 
        orig_factory = bzrlib.ui.ui_factory
586
 
        bzrlib.ui.ui_factory = ui
587
 
        try:
588
 
            ld2.break_lock()
589
 
            self.assertLength(1, ui.prompts)
590
 
            self.assertEqual('boolean', ui.prompts[0][0])
591
 
            self.assertStartsWith(ui.prompts[0][1], 'Break (corrupt LockDir')
592
 
            self.assertRaises(LockBroken, ld.unlock)
593
 
        finally:
594
 
            bzrlib.ui.ui_factory = orig_factory
 
584
        self.overrideAttr(bzrlib.ui, 'ui_factory', ui)
 
585
        ld2.break_lock()
 
586
        self.assertLength(1, ui.prompts)
 
587
        self.assertEqual('boolean', ui.prompts[0][0])
 
588
        self.assertStartsWith(ui.prompts[0][1], 'Break (corrupt LockDir')
 
589
        self.assertRaises(LockBroken, ld.unlock)
595
590
 
596
591
    def test_break_lock_missing_info(self):
597
592
        """break_lock works even if the info file is missing (and tells the UI
669
664
        ld1.unlock()
670
665
 
671
666
    def test_lock_permission(self):
 
667
        self.requireFeature(features.not_running_as_root)
672
668
        if not osutils.supports_posix_readonly():
673
669
            raise tests.TestSkipped('Cannot induce a permission failure')
674
670
        ld1 = self.get_lock()
742
738
    def test_corrupt_lockdir_info(self):
743
739
        """We can cope with corrupt (and thus unparseable) info files."""
744
740
        # This seems like a fairly common failure case too - see
745
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/619872> for instance.
 
741
        # <https://bugs.launchpad.net/bzr/+bug/619872> for instance.
746
742
        # In particular some systems tend to fill recently created files with
747
743
        # nul bytes after recovering from a system crash.
748
744
        t = self.get_transport()