~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge prerequisite branch and tweak test to be more compact and faster.

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