24
24
import bzrlib.branch
25
import bzrlib.bzrdir as bzrdir
26
35
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
27
36
from bzrlib.check import check
28
import bzrlib.errors as errors
29
37
from bzrlib.errors import (FileExists,
32
40
UninitializableFormat,
35
import bzrlib.repository as repository
36
43
import bzrlib.revision
37
44
from bzrlib.tests import (
43
50
from bzrlib.trace import mutter
44
import bzrlib.transactions as transactions
45
import bzrlib.transport as transport
46
51
from bzrlib.transport import get_transport
47
import bzrlib.ui as ui
48
52
from bzrlib.upgrade import upgrade
49
import bzrlib.workingtree as workingtree
52
55
class TestCaseWithBzrDir(TestCaseWithTransport):
1335
1338
unused_repo = thisdir.create_repository()
1336
1339
master.lock_write()
1337
1340
unused_repo.lock_write()
1338
# two yes's : branch and repository. If the repo in this
1339
# dir is inappropriately accessed, 3 will be needed, and
1340
# we'll see that because the stream will be fully consumed
1341
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1342
master.bzrdir.break_lock()
1343
# only two ys should have been read
1344
self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1345
# we should be able to lock a newly opened branch now
1346
branch = master.bzrdir.open_branch()
1349
# we should not be able to lock the repository in thisdir as its still
1350
# held by the explicit lock we took, and the break lock should not have
1352
repo = thisdir.open_repository()
1353
self.assertRaises(errors.LockContention, repo.lock_write)
1354
unused_repo.unlock()
1342
# two yes's : branch and repository. If the repo in this
1343
# dir is inappropriately accessed, 3 will be needed, and
1344
# we'll see that because the stream will be fully consumed
1345
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1346
master.bzrdir.break_lock()
1347
# only two ys should have been read
1348
self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1349
# we should be able to lock a newly opened branch now
1350
branch = master.bzrdir.open_branch()
1353
# we should not be able to lock the repository in thisdir as its still
1354
# held by the explicit lock we took, and the break lock should not have
1356
repo = thisdir.open_repository()
1357
orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
1359
lockdir._DEFAULT_TIMEOUT_SECONDS = 1
1360
self.assertRaises(errors.LockContention, repo.lock_write)
1362
lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
1364
unused_repo.unlock()
1355
1365
self.assertRaises(errors.LockBroken, master.unlock)
1357
1367
def test_break_lock_tree(self):