~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_locking.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    lock_helpers,
26
26
    per_branch,
27
27
    )
28
 
from bzrlib.tests.matchers import *
29
28
 
30
29
 
31
30
class TestBranchLocking(per_branch.TestCaseWithBranch):
292
291
 
293
292
    def test_lock_write_returns_None_refuses_token(self):
294
293
        branch = self.make_branch('b')
295
 
        token = branch.lock_write().branch_token
 
294
        token = branch.lock_write()
296
295
        try:
297
296
            if token is not None:
298
297
                # This test does not apply, because this lockable supports
305
304
 
306
305
    def test_reentering_lock_write_raises_on_token_mismatch(self):
307
306
        branch = self.make_branch('b')
308
 
        token = branch.lock_write().branch_token
 
307
        token = branch.lock_write()
309
308
        try:
310
309
            if token is None:
311
310
                # This test does not apply, because this lockable refuses
322
321
 
323
322
    def test_lock_write_with_nonmatching_token(self):
324
323
        branch = self.make_branch('b')
325
 
        token = branch.lock_write().branch_token
 
324
        token = branch.lock_write()
326
325
        try:
327
326
            if token is None:
328
327
                # This test does not apply, because this branch refuses
345
344
        """Test that a branch can be locked with a token, if it is already
346
345
        locked by that token."""
347
346
        branch = self.make_branch('b')
348
 
        token = branch.lock_write().branch_token
 
347
        token = branch.lock_write()
349
348
        try:
350
349
            if token is None:
351
350
                # This test does not apply, because this branch refuses tokens.
369
368
        # If lock_write did not physically acquire the lock (because it was
370
369
        # passed some tokens), then unlock should not physically release it.
371
370
        branch = self.make_branch('b')
372
 
        token = branch.lock_write().branch_token
 
371
        token = branch.lock_write()
373
372
        try:
374
373
            if token is None:
375
374
                # This test does not apply, because this lockable refuses
391
390
        # to lock with a token that is no longer valid (because the original
392
391
        # lock was released).
393
392
        branch = self.make_branch('b')
394
 
        token = branch.lock_write().branch_token
 
393
        token = branch.lock_write()
395
394
        branch.unlock()
396
395
        if token is None:
397
396
            # This test does not apply, because this lockable refuses
398
397
            # tokens.
399
398
            return
400
 
        self.assertRaises(errors.TokenMismatch, branch.lock_write, token=token)
 
399
 
 
400
        self.assertRaises(errors.TokenMismatch,
 
401
                          branch.lock_write, token=token)
401
402
 
402
403
    def test_lock_write_reenter_with_token(self):
403
404
        branch = self.make_branch('b')
404
 
        token = branch.lock_write().branch_token
 
405
        token = branch.lock_write()
405
406
        try:
406
407
            if token is None:
407
408
                # This test does not apply, because this lockable refuses
423
424
        branch = self.make_branch('b')
424
425
        # Lock the branch, then use leave_lock_in_place so that when we
425
426
        # unlock the branch the lock is still held on disk.
426
 
        token = branch.lock_write().branch_token
 
427
        token = branch.lock_write()
427
428
        try:
428
429
            if token is None:
429
430
                # This test does not apply, because this repository refuses lock
444
445
    def test_dont_leave_lock_in_place(self):
445
446
        branch = self.make_branch('b')
446
447
        # Create a lock on disk.
447
 
        token = branch.lock_write().branch_token
 
448
        token = branch.lock_write()
448
449
        try:
449
450
            if token is None:
450
451
                # This test does not apply, because this branch refuses lock
496
497
        branch.lock_read()
497
498
        branch.unlock()
498
499
 
499
 
    def test_lock_read_returns_unlockable(self):
500
 
        branch = self.make_branch('b')
501
 
        self.assertThat(branch.lock_read, ReturnsUnlockable(branch))
502
 
 
503
500
    def test_lock_write_locks_repo_too(self):
504
501
        if isinstance(self.branch_format, _mod_branch.BzrBranchFormat4):
505
502
            # Branch format 4 is combined with the repository, so this test
526
523
        finally:
527
524
            branch.unlock()
528
525
 
529
 
    def test_lock_write_returns_unlockable(self):
530
 
        branch = self.make_branch('b')
531
 
        self.assertThat(branch.lock_write, ReturnsUnlockable(branch))
532
 
 
533
 
    def test_lock_write_raises_in_lock_read(self):
534
 
        branch = self.make_branch('b')
535
 
        branch.lock_read()
536
 
        self.addCleanup(branch.unlock)
537
 
        err = self.assertRaises(errors.ReadOnlyError, branch.lock_write)
538
 
 
539
526
    def test_lock_and_unlock_leaves_repo_unlocked(self):
540
527
        branch = self.make_branch('b')
541
528
        branch.lock_write()